Скрыть код от пользователей, который располагается выше названия блога.

Здравствуйте, редактирую файл topic_part_header.tpl в плагине MultiBlogs.

Если разместить этот код:

{if $oUserCurrent and ($oUserCurrent->isAdministrator())}
код...
{/if}


выше этого:

<li class="topic-info-author">
    <a rel="author" href="{$oUser->getUserWebPath()}">{$oUser->getLogin()}</a>
</li>
<li class="topic-info-author">
    <a href="{$oUser->getUserWebPath()}"><img src="{$oUser->getProfileAvatarPath(24)}" alt="avatar" class="avatar" /></a>
</li>
<li class="category"><a>Shared to </a>
    {foreach from=$aBlogs item=oBlog}
        <a href="{$oBlog->getUrlFull()}" class="topic-blog">{$oBlog->getTitle()|escape:'html'}</a>
    {/foreach}
</li>


То получаю следующую ошибку:

Fatal error: Call to a member function getUserIsAdministrator()


Может быть кто нибудь знает как это решить?

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

avatar
приводите полный пример кода, что за конспирация?
avatar
{assign var="aBlogs" value=$oTopic->getMultiblogs()}
{assign var="oUser" value=$oTopic->getUser()}
{assign var="oVote" value=$oTopic->getVote()}
{assign var="oFavourite" value=$oTopic->getFavourite()}
<!-- fchn topic - start -->

<table class="topic topic-type-{$oTopic->getType()} js-topic">
<tbody>
<tr>
<td class="votecell">

				{assign var="bVoteInfoShow" value=false}
			
			<li class="topic-info-vote">
								<div id="vote_area_topic_{$oTopic->getId()}" class="vote-topic
																	{if $oVote || ($oUserCurrent && $oTopic->getUserId() == $oUserCurrent->getId()) || strtotime($oTopic->getDateAdd()) < $smarty.now-$oConfig->GetValue('acl.vote.topic.limit_time')}
																		{if $oTopic->getRating() > 0}
																			vote-count-positive
																		{elseif $oTopic->getRating() < 0}
																			vote-count-negative
																		{elseif $oTopic->getRating() == 0}
																			vote-count-zero
																		{/if}
																	{/if}
																	
																	{if !$oUserCurrent or ($oUserCurrent && $oTopic->getUserId() != $oUserCurrent->getId())}
																		vote-not-self
																	{/if}
																	
																	{if $oVote} 
																		voted
																		
																		{if $oVote->getDirection() > 0}
																			voted-up
																		{elseif $oVote->getDirection() < 0}
																			voted-down
																		{elseif $oVote->getDirection() == 0}
																			voted-zero
																		{/if}
																	{else}
																		not-voted
																	{/if}
																	
																	{if (strtotime($oTopic->getDateAdd()) < $smarty.now-$oConfig->GetValue('acl.vote.topic.limit_time') && !$oVote) || ($oUserCurrent && $oTopic->getUserId() == $oUserCurrent->getId())}
																		vote-nobuttons
																	{/if}
																	
																	{if strtotime($oTopic->getDateAdd()) > $smarty.now-$oConfig->GetValue('acl.vote.topic.limit_time')}
																		vote-not-expired
																	{/if}

																	{if $bVoteInfoShow}js-infobox-vote-topic{/if}">
					<div class="vote-item vote-up" onclick="return ls.vote.vote({$oTopic->getId()},this,1,'topic');"><i></i></div>
					
					<div class="vote-item vote-count" title="{$aLang.topic_vote_count}: {$oTopic->getCountVote()}">
						<span id="vote_total_topic_{$oTopic->getId()}" class="
								{if $oTopic->getRating() > 0}
									vote-count-positive
								{elseif $oTopic->getRating() < 0}
									vote-count-negative
								{elseif $oTopic->getRating() == 0}
									vote-count-zero
								{/if}
								">
							{$oTopic->getRating()}
						</span>
					</div>
					
					<div class="vote-item vote-down" onclick="return ls.vote.vote({$oTopic->getId()},this,-1,'topic');"><i></i></div>

					{if $bVoteInfoShow}
						<div id="vote-info-topic-{$oTopic->getId()}" style="display: none;">
							<ul class="vote-topic-info">
								<li><i class="icon-plus icon-white"></i> {$oTopic->getCountVoteUp()}</li>
								<li><i class="icon-minus icon-white"></i> {$oTopic->getCountVoteDown()}</li>
								<li><i class="icon-eye-open icon-white"></i> {$oTopic->getCountRead()}</li>
								{hook run='topic_show_vote_stats' topic=$oTopic}
							</ul>
						</div>
					{/if}


----------------------------------------

{if $oUserCurrent and ($oUserCurrent->getId()==$oTopic->getUserId() or $oUserCurrent->isAdministrator() or $oBlog->getUserIsAdministrator() or $oBlog->getUserIsModerator() or $oBlog->getOwnerId()==$oUserCurrent->getId())}

				{if $oUserCurrent and ($oUserCurrent->isAdministrator() or $oBlog->getUserIsAdministrator() or $oBlog->getOwnerId()==$oUserCurrent->getId())}
					<div class="vote-item edit"><a href="{cfg name='path.root.web'}/{$oTopic->getType()}/edit/{$oTopic->getId()}/" title="{$aLang.topic_edit}" class="actions-edit"><i></i></a></div>
				{/if}
					<div class="vote-item delete"><a href="{router page='topic'}delete/{$oTopic->getId()}/?security_ls_key={$LIVESTREET_SECURITY_KEY}" title="{$aLang.topic_delete}" onclick="return confirm('{$aLang.topic_delete_confirm}');" class="actions-delete"><i></i></a></div>
		{/if}


----------------------------------------
				</div>
			</li>
</td>			

<td class="postcell">
<article>
	<header class="topic-header">
    	              
		
			{if $bTopicList}
				<a class="titleh1" href="{$oTopic->getUrl()}" {if $oTopic->getType() == 'link'}title="{$aLang.topic_link}"{/if}>{$oTopic->getTitle()|escape:'html'}</a>
			{else}
				<h1 class="title">{$oTopic->getTitle()|escape:'html'}</h1>
			{/if}
            {if $oTopic->getPublish() == 0}   
				<i class="icon icon-eye-close" title="{$aLang.topic_unpublish}"></i>
			{/if}
		        
        
        	<ul class="topic-additional-info">
				<li class="topic-info-author">
					<a rel="author" href="{$oUser->getUserWebPath()}">{$oUser->getLogin()}</a>
				</li>
				<li class="topic-info-author">
					<a href="{$oUser->getUserWebPath()}"><img src="{$oUser->getProfileAvatarPath(24)}" alt="avatar" class="avatar" /></a>
				</li>
            	<li class="category"><a>Shared to </a>
					{foreach from=$aBlogs item=oBlog}
						<a href="{$oBlog->getUrlFull()}" class="topic-blog">{$oBlog->getTitle()|escape:'html'}</a> 
					{/foreach}
				</li>				
                <li class="date">
                	<time datetime="{date_format date=$oTopic->getDateAdd() format='c'}" title="{date_format date=$oTopic->getDateAdd() format='M j, Y'}">
					{date_format date=$oTopic->getDateAdd() hours_back="12" minutes_back="60" now="60" day="day g:i A" format="M j, Y"}</time>
                </li>
				{if $oTopic->getsourcecontent() != ""}
				{if $oTopic->getType() == 'gif' or $oTopic->getType() == 'photoset'}<li class="source">
					<a href="http://{$oTopic->getsourcecontent()|escape:'html'}" target="_blank">Source</a>
				</li>{/if}
				{/if}		

				
            </ul>

	</header>
avatar
приведите участок кода до модификации и после, полный текст ошибки и что именно вы хотите сделать
avatar
Я не умею пользоваться гит хаб, поэтому залил на дропбокс -)

dl.dropboxusercontent.com/u/6892731/topic_part_header.txt

вот полный файл topic_part_header.tpl, участок кода, который был добавлен выделен стрелочками (этот код отсутствовал в файле до модификации).

Я хочу вставить 2 кнопки «редактировать» и «удалить» топик именно в это место.

Fatal error: Call to a member function getUserIsAdministrator() on a non-object in /var/www/мой-сайт/templates/compiled/шаблон/9379624bbb45e2aa3a64b9beccf045ce42fc14e4.file.topic_part_header.tpl.php on line 135


Файл:

dl.dropboxusercontent.com/u/6892731/9379624bbb45e2aa3a64b9beccf045ce42fc14e4.file.topic_part_header.tpl.php
avatar
вы пытаетесь вставить кусок кода из движка в сторонний плагин, у которого своя собственная логика и выражение:
$oBlog->getUserIsAdministrator() or $oBlog->getUserIsModerator()

не работает т.к. нет переменной $oBlog. обратитесь к автору плагина.
avatar
Можно просто assign var.
avatar
причем здесь метод? там нет понятия «блога», а есть их список.
avatar
Если пользователю нужно получить определенный блог, то пусть его получит через метод GetBlogById.
avatar
подумайте ещё
avatar
Решил проблему вот так:

{if $oTopic->getIsAllowAction()}
    {if $oUserCurrent->isAdministrator() }
    {if $oTopic->getIsAllowEdit()}
  • {/if} {/if} {if $oTopic->getIsAllowDelete()}
  • {/if}
{/if}
avatar
Опять в код не обернул, прошу прощения -)

{if $oTopic->getIsAllowAction()}
<ul class="topic-main-info">    
    {if $oUserCurrent->isAdministrator() }
        {if $oTopic->getIsAllowEdit()}
            <li class="vote-item edit"><a href="{$oTopic->getUrlEdit()}" title="{$aLang.topic_edit}" class="actions-edit"><i></i></a></li>
        {/if}       
    {/if}    
        {if $oTopic->getIsAllowDelete()}
            <li class="vote-item delete"><a href="{router page='topic'}delete/{$oTopic->getId()}/?security_ls_key={$LIVESTREET_SECURITY_KEY}" title="{$aLang.topic_delete}" onclick="return confirm('{$aLang.topic_delete_confirm}');" class="actions-delete"><i></i></a></li>
        {/if}
</ul>
{/if}
avatar
А зачем так:
{if $oUserCurrent and ($oUserCurrent->isAdministrator())}

Скобки не нужны после and.
avatar
Скобки не нужны после and.
докажите утверждение :)
avatar
{if $oUserCurrent and $oUserCurrent->isAdministrator()}

Зачем лишние скобки?
avatar
Здравствуйте, появился автор плагина. :)
Как правильно заметил PSNet в том шаблоне нет понятия Блога а есть понятие масив блогов. Поэтому давайте определимся что именно вы хотите сделать. как вариант вы можете проверить ВСЕ блоги из списка
{foreach from=$aBlogs item=oBlog}
{$oBlog->getUserIsAdministrator() or $oBlog->getUserIsModerator()}
… логика работы
{/foreach}
Только зарегистрированные и авторизованные пользователи могут оставлять комментарии.