Synio: делаем удобную кнопку добавления в друзья

Тестировал данный шаблон и наткнулся на следующую пробелму: при открытии профиля пользователя кнопка «добавить в друзья» где-то снизу и её совсем не видно.
Логично вывести её на верх экрана, вот сюда:

Реализовал я это так:

В шаблон профиля (/templates/skin/synio/actions/ActionProfile/profile_top.tpl) добавил фрагмент кода добавления друзья:
{if $oUserProfile->getUserFriend() and ($oUserProfile->getUserFriend()->getFriendStatus()==$USER_FRIEND_ACCEPT+$USER_FRIEND_OFFER or $oUserProfile->getUserFriend()->getFriendStatus()==$USER_FRIEND_ACCEPT+$USER_FRIEND_ACCEPT)}
	<li> </li>
	{elseif $oUserProfile->getUserFriend() and $oUserProfile->getUserFriend()->getStatusTo()==$USER_FRIEND_REJECT and $oUserProfile->getUserFriend()->getStatusFrom()==$USER_FRIEND_OFFER and $oUserProfile->getUserFriend()->getUserTo()==$oUserCurrent->getId()}
	<a href="#" title="{$aLang.user_friend_add}" onclick="return ls.user.addFriend(this,{$oUserProfile->getId()},'accept');"><button type="submit"  class="button button-action button-action-add-friend"><i class="icon-synio-add-friend"></i><span>{$aLang.user_friend_add}</span></button></a>
	{elseif $oUserProfile->getUserFriend() and $oUserProfile->getUserFriend()->getFriendStatus()==$USER_FRIEND_OFFER+$USER_FRIEND_REJECT and $oUserProfile->getUserFriend()->getUserTo()!=$oUserCurrent->getId()}							
	<li> </li>
	{elseif $oUserProfile->getUserFriend() and $oUserProfile->getUserFriend()->getFriendStatus()==$USER_FRIEND_OFFER+$USER_FRIEND_NULL and $oUserProfile->getUserFriend()->getUserFrom()==$oUserCurrent->getId()}						
	<li> </li>
	{elseif $oUserProfile->getUserFriend() and $oUserProfile->getUserFriend()->getFriendStatus()==$USER_FRIEND_OFFER+$USER_FRIEND_NULL and $oUserProfile->getUserFriend()->getUserTo()==$oUserCurrent->getId()}
	<a href="#" title="{$aLang.user_friend_add}" onclick="return ls.user.addFriend(this,{$oUserProfile->getId()},'accept');"><button type="submit"  class="button button-action button-action-add-friend"><i class="icon-synio-add-friend"></i><span>{$aLang.user_friend_add}</span></button></a>
    {elseif !($oUserProfile->getUserFriend())}
	<div id="add_friend_form" class="modal">
		<header class="modal-header">
			<h3>{$aLang.profile_add_friend}</h3>
			<a href="#" class="close jqmClose"></a>
		</header>

		<form onsubmit="return ls.user.addFriend(this,{$oUserProfile->getId()},'add');" class="modal-content">
			<p><label for="add_friend_text">{$aLang.user_friend_add_text_label}</label>
			<textarea id="add_friend_text" rows="3" class="input-text input-width-full"></textarea></p>

			<button type="submit"  class="button button-primary">{$aLang.user_friend_add_submit}</button>
		</form>
	</div>
	<a href="#" title="{$aLang.user_friend_add}" onclick="return ls.user.addFriend(this,{$oUserProfile->getId()},'link');"><button type="submit"  class="button button-action button-action-add-friend"><i class="icon-synio-add-friend"></i><span>{$aLang.user_friend_add}</span></button></a>
	{else}
	<a href="#" title="{$aLang.user_friend_add}" onclick="return ls.user.addFriend(this,{$oUserProfile->getId()},'link');"><button type="submit"  class="button button-action button-action-add-friend"><i class="icon-synio-add-friend"></i><span>{$aLang.user_friend_add}</span></button></a>
	{/if}


Вставляется в 44-ю строку после выражения (код будет обернут в данный if):
{if $oUserCurrent && $oUserCurrent->getId()!=$oUserProfile->getId()}
	


Получилось вот так:

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

avatar
круто просто и давно уже смотрел туда, спасибо!
avatar
Годно! Два вопроса — внизу остается ли пункт «добавить в друзья»? И сразу второй вопрос — этот хак подойдет для шаблона стартер кит и корректен ли хак по отношению к движку, верстке и тд? Заранее спасибо.
avatar
да, остался, нижний пункт я не убирал. При желании его можно убрать, удалив из файла AptionProfile/sidebabar.tpl определенный кусок кода.
Для стартер кит — не знаю, не тестировал. Хак корректен, т.к. я тут просто копирование кода элемента с одного места в другое.
avatar
то есть добавив в одно место и тоже самое вырезав из другого (чтобы не дублировалось) — ты просто переопределяешь движку куда выводить это и все, верно?
avatar
это простой код который вставленный в кнопочку.
avatar
А вот меня интересует на первом скрине «Место». Как я понял это место пользователя, а так же на сколько позиций он упали или поднялся за какое-то время. Интересно как такое реализовать
avatar
это сделано бесплатным плагином «Мнения» livestreetcms.com/addons/view/483/

Его, кстати, в ближайшее время тоже планирую «допилить», результаты выложу.
avatar
С помощью его можно только место выводить, а сами мнения не включать?
avatar
можно, в конфиге плагина настраивается
avatar
скажите позязя, а в чём «допилинг» планируется выразить?
avatar
Сейчас, при появлении нового мнения, пользователь не узнает об этом, пока не зайдет в раздел «Мнения обо мне». Логично было бы допилить функционал так, что бы при появлении нового мнения у пользователя этот раздел как-то выделялся.
avatar
предложу выводить рядом с кнопкой "+1"
avatar
Стоп. Получается, что зайдя в свой профиль, я увижу кнопку «добавить в друзья», нажму ее и получу ошибку «ваш друг — это вы!»
avatar
вы можете уточнить -какие обстоятельства привели к этому, какой шаблон, как вы сделали предложенный ТСом хак и т.д. я хак сделал, но еще не пробовал — так что тревожьте общественность по делу))
avatar
Окей. ЛС последней версии, стандартный шаблон, хак сделан по правилам.

С другой стороны, можно и самому себе отправлять сообщения через /people, так что все это — в порядке вещей :)
avatar
Хм… проверил — хак действительно нерабочий, т.к. посылаешь запрос в дружбу самому себе. Уважаемый ТС — чего делать будем?)
avatar
Хак рабочий, проверено, самому себе в друзья нет возмонжости добавиться, т.к. кнопка добавления в друзья обернута в проверку
{if $oUserCurrent && $oUserCurrent->getId()!=$oUserProfile->getId()}


если кнопка «написать сообщение» в своем профиле у вас тоже показывается, то значит вы и её забыли обернуть в проверку.
avatar
Хорошее дело эта кнопка, а то мало, кто на ссылку смотрит.
avatar
Да, все корректн работает. Просто нужно было сразу акцентировать на том, что нужно именно в обертку. В итоге, выходит что-то вроде
{if $oUserCurrent && $oUserCurrent->getId()!=$oUserProfile->getId()}
		<a href="{router page='talk'}add/?talk_users={$oUserProfile->getLogin()}"><button type="submit"  class="button button-action button-action-send-message"><i class="icon-synio-send-message"></i><span>{$aLang.user_write_prvmsg}</span></button></a>
	{if $oUserProfile->getUserFriend() and ($oUserProfile->getUserFriend()->getFriendStatus()==$USER_FRIEND_ACCEPT+$USER_FRIEND_OFFER or $oUserProfile->getUserFriend()->getFriendStatus()==$USER_FRIEND_ACCEPT+$USER_FRIEND_ACCEPT)}
	<li> </li>
	{elseif $oUserProfile->getUserFriend() and $oUserProfile->getUserFriend()->getStatusTo()==$USER_FRIEND_REJECT and $oUserProfile->getUserFriend()->getStatusFrom()==$USER_FRIEND_OFFER and $oUserProfile->getUserFriend()->getUserTo()==$oUserCurrent->getId()}
	<a href="#" title="{$aLang.user_friend_add}" onclick="return ls.user.addFriend(this,{$oUserProfile->getId()},'accept');"><button type="submit"  class="button button-action button-action-add-friend"><i class="icon-synio-add-friend"></i><span>{$aLang.user_friend_add}</span></button></a>
	{elseif $oUserProfile->getUserFriend() and $oUserProfile->getUserFriend()->getFriendStatus()==$USER_FRIEND_OFFER+$USER_FRIEND_REJECT and $oUserProfile->getUserFriend()->getUserTo()!=$oUserCurrent->getId()}							
	<li> </li>
	{elseif $oUserProfile->getUserFriend() and $oUserProfile->getUserFriend()->getFriendStatus()==$USER_FRIEND_OFFER+$USER_FRIEND_NULL and $oUserProfile->getUserFriend()->getUserFrom()==$oUserCurrent->getId()}						
	<li> </li>
	{elseif $oUserProfile->getUserFriend() and $oUserProfile->getUserFriend()->getFriendStatus()==$USER_FRIEND_OFFER+$USER_FRIEND_NULL and $oUserProfile->getUserFriend()->getUserTo()==$oUserCurrent->getId()}
	<a href="#" title="{$aLang.user_friend_add}" onclick="return ls.user.addFriend(this,{$oUserProfile->getId()},'accept');"><button type="submit"  class="button button-action button-action-add-friend"><i class="icon-synio-add-friend"></i><span>{$aLang.user_friend_add}</span></button></a>
    {elseif !($oUserProfile->getUserFriend())}
	<div id="add_friend_form" class="modal">
		<header class="modal-header">
			<h3>{$aLang.profile_add_friend}</h3>
			<a href="#" class="close jqmClose"></a>
		</header>

		<form onsubmit="return ls.user.addFriend(this,{$oUserProfile->getId()},'add');" class="modal-content">
			<p><label for="add_friend_text">{$aLang.user_friend_add_text_label}</label>
			<textarea id="add_friend_text" rows="3" class="input-text input-width-full"></textarea></p>

			<button type="submit"  class="button button-primary">{$aLang.user_friend_add_submit}</button>
		</form>
	</div>
	<a href="#" title="{$aLang.user_friend_add}" onclick="return ls.user.addFriend(this,{$oUserProfile->getId()},'link');"><button type="submit"  class="button button-action button-action-add-friend"><i class="icon-synio-add-friend"></i><span>{$aLang.user_friend_add}</span></button></a>
	{else}
	<a href="#" title="{$aLang.user_friend_add}" onclick="return ls.user.addFriend(this,{$oUserProfile->getId()},'link');"><button type="submit"  class="button button-action button-action-add-friend"><i class="icon-synio-add-friend"></i><span>{$aLang.user_friend_add}</span></button></a>
	{/if}
	{/if}

Тогда все работает правильно.
avatar
ок — тогда подскажите как минимум куда именно это все вставлять? Видите ли, уважаемый ТС — если вы забыли прокомментировать свои действия в предложенном хаке, подразумевая, что читатель поймет это сам — то увы, сие не совсем корректно. не все )и я в том числе) сильны в хаках\вызовах процедур\хуков и т.п. технических вещах. поэтому слепо скопировав ваш хак я неминуемо получил ошибку, о чём, собственно, и написал сюда же. Минусовать за неумение считаю неверным.
avatar
ок — тогда подскажите как минимум куда именно это все вставлять?


1. Заходим в файл, который находится по директории /templates/skin/synio/actions/ActionProfile/profile_top.tpl

2. Где-то в 45-50 строках видим следующий код:
{if $oUserCurrent && $oUserCurrent->getId()!=$oUserProfile->getId()}
     <a href="{router page='talk'}add/?talk_users={$oUserProfile->getLogin()}"><button type="submit"  class="button button-action button-action-send-message"><i class="icon-synio-send-message"></i><span>{$aLang.user_write_prvmsg}</span></button></a><br />
* Сюда вставляем код из пункта 3
*/
{/if}


3. Теперь исходный код добавления в друзья:
{if $oUserProfile->getUserFriend() and ($oUserProfile->getUserFriend()->getFriendStatus()==$USER_FRIEND_ACCEPT+$USER_FRIEND_OFFER or $oUserProfile->getUserFriend()->getFriendStatus()==$USER_FRIEND_ACCEPT+$USER_FRIEND_ACCEPT)}
	<li> </li>
	{elseif $oUserProfile->getUserFriend() and $oUserProfile->getUserFriend()->getStatusTo()==$USER_FRIEND_REJECT and $oUserProfile->getUserFriend()->getStatusFrom()==$USER_FRIEND_OFFER and $oUserProfile->getUserFriend()->getUserTo()==$oUserCurrent->getId()}
	<a href="#" title="{$aLang.user_friend_add}" onclick="return ls.user.addFriend(this,{$oUserProfile->getId()},'accept');"><button type="submit"  class="button button-action button-action-add-friend"><i class="icon-synio-add-friend"></i><span>{$aLang.user_friend_add}</span></button></a>
	{elseif $oUserProfile->getUserFriend() and $oUserProfile->getUserFriend()->getFriendStatus()==$USER_FRIEND_OFFER+$USER_FRIEND_REJECT and $oUserProfile->getUserFriend()->getUserTo()!=$oUserCurrent->getId()}							
	<li> </li>
	{elseif $oUserProfile->getUserFriend() and $oUserProfile->getUserFriend()->getFriendStatus()==$USER_FRIEND_OFFER+$USER_FRIEND_NULL and $oUserProfile->getUserFriend()->getUserFrom()==$oUserCurrent->getId()}						
	<li> </li>
	{elseif $oUserProfile->getUserFriend() and $oUserProfile->getUserFriend()->getFriendStatus()==$USER_FRIEND_OFFER+$USER_FRIEND_NULL and $oUserProfile->getUserFriend()->getUserTo()==$oUserCurrent->getId()}
	<a href="#" title="{$aLang.user_friend_add}" onclick="return ls.user.addFriend(this,{$oUserProfile->getId()},'accept');"><button type="submit"  class="button button-action button-action-add-friend"><i class="icon-synio-add-friend"></i><span>{$aLang.user_friend_add}</span></button></a>
    {elseif !($oUserProfile->getUserFriend())}
	<div id="add_friend_form" class="modal">
		<header class="modal-header">
			<h3>{$aLang.profile_add_friend}</h3>
			<a href="#" class="close jqmClose"></a>
		</header>

		<form onsubmit="return ls.user.addFriend(this,{$oUserProfile->getId()},'add');" class="modal-content">
			<p><label for="add_friend_text">{$aLang.user_friend_add_text_label}</label>
			<textarea id="add_friend_text" rows="3" class="input-text input-width-full"></textarea></p>

			<button type="submit"  class="button button-primary">{$aLang.user_friend_add_submit}</button>
		</form>
	</div>
	<a href="#" title="{$aLang.user_friend_add}" onclick="return ls.user.addFriend(this,{$oUserProfile->getId()},'link');"><button type="submit"  class="button button-action button-action-add-friend"><i class="icon-synio-add-friend"></i><span>{$aLang.user_friend_add}</span></button></a>
	{else}
	<a href="#" title="{$aLang.user_friend_add}" onclick="return ls.user.addFriend(this,{$oUserProfile->getId()},'link');"><button type="submit"  class="button button-action button-action-add-friend"><i class="icon-synio-add-friend"></i><span>{$aLang.user_friend_add}</span></button></a>
	{/if}


Вставляем до {/if}, чтобы условие проверки работало и не было возможности добавить самого себя в друзья.
avatar
Спасибо за развернутый ответ — будем пробовать.
avatar
у меня все верно написано, просто надо внимательнее читать инструкции
avatar
у вас написано что предложенный код нужно вставить туда-то. без каких-либо уточнений. я вставил, найдя нужную строчку. и получил баг. только и всего, сейчас если новй хак это исправит-то вообще чудесн.
avatar
и я не писал что у вас что-то неверно. я констатировал факт, не более того.
avatar
А как правильно добавить эту кнопку в user_list.tpl?
avatar
atsuudo можете скинуть весь /templates/skin/synio/actions/ActionProfile/profile_top.tpl
У меня что то не работает (((
avatar
Вообще, добавление в друзья нужно сделать
1. Без сопутствующего сообщения (кнопка срабатывает тут же)
2. В инбокс приходит письмо, что «вася хочет добавить вас в друзья» и 2 кнопки: добавить в друзья и оставить в подписчиках.

Все равно при добавлении в друзья никто не пишет ничего в этом окошке, ну смайлик какой то.
avatar
Логично. вообще узким местом лс является отвратительно неюзабельная часть, относящаяся к личному пространству юзера, все остальное вполне норм «искаропки», как говорится.
avatar
Если у Вас работает кнопка можете выложить весь /templates/skin/synio/actions/ActionProfile/profile_top.tpl
avatar
Вот весь код profile_top.tpl (рабочий):
<div class="profile">
	{hook run='profile_top_begin' oUserProfile=$oUserProfile}
	
	<div class="vote-profile">
		<div id="vote_area_user_{$oUserProfile->getId()}" class="vote-topic
																	{if $oUserProfile->getRating() > 0}
																		vote-count-positive
																	{elseif $oUserProfile->getRating() < 0}
																		vote-count-negative
																	{elseif $oUserProfile->getRating() == 0}
																		vote-count-zero
																	{/if}
																	
																	{if $oVote} 
																		voted 
																		
																		{if $oVote->getDirection() > 0}
																			voted-up
																		{elseif $oVote->getDirection() < 0}
																			voted-down
																		{/if}
																	{else}
																		not-voted
																	{/if}
																	
																	{if ($oUserCurrent && $oUserProfile->getId() == $oUserCurrent->getId()) || !$oUserCurrent}
																		vote-nobuttons
																	{/if}">
			<div class="vote-item vote-down" onclick="return ls.vote.vote({$oUserProfile->getId()},this,-1,'user');"><span><i></i></span></div>
			<div class="vote-item vote-count" title="{$aLang.user_vote_count}: {$oUserProfile->getCountVote()}">
				<span id="vote_total_user_{$oUserProfile->getId()}">{if $oUserProfile->getRating() > 0}+{/if}{$oUserProfile->getRating()}</span>
			</div>
			<div class="vote-item vote-up" onclick="return ls.vote.vote({$oUserProfile->getId()},this,1,'user');"><span><i></i></span></div>
		</div>
		<div class="vote-label">{$aLang.user_rating}</div>
	</div>
	
	<div class="strength">
		<div class="count" id="user_skill_{$oUserProfile->getId()}">{$oUserProfile->getSkill()}</div>
		<div class="vote-label">{$aLang.user_skill}</div>
	</div>

	{if $oUserCurrent && $oUserCurrent->getId()!=$oUserProfile->getId()}
		<a href="{router page='talk'}add/?talk_users={$oUserProfile->getLogin()}"><button type="submit"  class="button button-action button-action-send-message"><i class="icon-synio-send-message"></i><span>{$aLang.user_write_prvmsg}</span></button></a>
	
    {if $oUserProfile->getUserFriend() and ($oUserProfile->getUserFriend()->getFriendStatus()==$USER_FRIEND_ACCEPT+$USER_FRIEND_OFFER or $oUserProfile->getUserFriend()->getFriendStatus()==$USER_FRIEND_ACCEPT+$USER_FRIEND_ACCEPT)}
	
	{elseif $oUserProfile->getUserFriend() and $oUserProfile->getUserFriend()->getStatusTo()==$USER_FRIEND_REJECT and $oUserProfile->getUserFriend()->getStatusFrom()==$USER_FRIEND_OFFER and $oUserProfile->getUserFriend()->getUserTo()==$oUserCurrent->getId()}
	<a href="#" title="{$aLang.user_friend_add}" onclick="return ls.user.addFriend(this,{$oUserProfile->getId()},'accept');"><button type="submit"  class="button button-action button-action-add-friend"><i class="icon-synio-add-friend"></i><span>{$aLang.user_friend_add}</span></button></a>
	{elseif $oUserProfile->getUserFriend() and $oUserProfile->getUserFriend()->getFriendStatus()==$USER_FRIEND_OFFER+$USER_FRIEND_REJECT and $oUserProfile->getUserFriend()->getUserTo()!=$oUserCurrent->getId()}							
	
	{elseif $oUserProfile->getUserFriend() and $oUserProfile->getUserFriend()->getFriendStatus()==$USER_FRIEND_OFFER+$USER_FRIEND_NULL and $oUserProfile->getUserFriend()->getUserFrom()==$oUserCurrent->getId()}						
	
	{elseif $oUserProfile->getUserFriend() and $oUserProfile->getUserFriend()->getFriendStatus()==$USER_FRIEND_OFFER+$USER_FRIEND_NULL and $oUserProfile->getUserFriend()->getUserTo()==$oUserCurrent->getId()}
	<a href="#" title="{$aLang.user_friend_add}" onclick="return ls.user.addFriend(this,{$oUserProfile->getId()},'accept');"><button type="submit"  class="button button-action button-action-add-friend"><i class="icon-synio-add-friend"></i><span>{$aLang.user_friend_add}</span></button></a>
    {elseif !($oUserProfile->getUserFriend())}
	<div id="add_friend_form" class="modal">
		<header class="modal-header">
			<h3>{$aLang.profile_add_friend}</h3>
			<a href="#" class="close jqmClose"></a>
		</header>

		<form onsubmit="return ls.user.addFriend(this,{$oUserProfile->getId()},'add');" class="modal-content">
			<p><label for="add_friend_text">{$aLang.user_friend_add_text_label}</label>
			<textarea id="add_friend_text" rows="3" class="input-text input-width-full"></textarea></p>

			<button type="submit"  class="button button-primary">{$aLang.user_friend_add_submit}</button>
		</form>
	</div>
	<a href="#" title="{$aLang.user_friend_add}" onclick="return ls.user.addFriend(this,{$oUserProfile->getId()},'link');"><button type="submit"  class="button button-action button-action-add-friend"><i class="icon-synio-add-friend"></i><span>{$aLang.user_friend_add}</span></button></a>
	{else}
	<a href="#" title="{$aLang.user_friend_add}" onclick="return ls.user.addFriend(this,{$oUserProfile->getId()},'link');"><button type="submit"  class="button button-action button-action-add-friend"><i class="icon-synio-add-friend"></i><span>{$aLang.user_friend_add}</span></button></a>
	{/if}

    {/if}

	<h2 class="page-header user-login word-wrap {if !$oUserProfile->getProfileName()}no-user-name{/if}" itemprop="nickname">{$oUserProfile->getLogin()}</h2>
	
	{if $oUserProfile->getProfileName()}
		<p class="user-name" itemprop="name">{$oUserProfile->getProfileName()|escape:'html'}</p>
	{/if}
	
	{hook run='profile_top_end' oUserProfile=$oUserProfile}
</div>
avatar
Спасибо, но не получилось (
Я уже обращался и к программистам…
После замены кода на сайте ни чего не меняется
Кешь везде чистил и в браузере и в compiled, cache
avatar
попробуйте отключить плагины
avatar
Спасибо! Получилось!
Стоял плагин
«Simple Rating» — упрощает рейтинговую систему
avatar
Что бы работал плагин нужно править в плагине
plugins/simplerating/templates/skin/synio/actions/ActionProfile/profile_top.tpl
avatar
почему эта кнопка игнорирует окно комментария к добавлению в друзья?
avatar
а оно должно быть?
тут функционал точно такой же, как и при нажатии ссылки «добавить в друзья» со страницы пользователя, просто он повешен на кнопку.
avatar
Вы когда нажимаете на ссылочку внизу профиля то всплывает окно с надписью: Представьтесь пожалуйста. А когда жмешь кнопочку, созданную по этому коду, запрос отправляется на прямую. Во всяком случае у меня так.
avatar
сейчас проверил, вы правы, действительно, при добавлении в друзья должно появиться окошко «Представьтесь пожалуйста», которое я при реализации упустил. Но это не критично, при желании всегда можно написать сообщение =)
avatar
конечно можно, мелочь, но все же не по феншую =)
Только зарегистрированные и авторизованные пользователи могут оставлять комментарии.