Toggle User Profile Links

Hello.

I have managed to make user profile pages link to the registration page for unregistered visitors while also making them accessible for a registered logged in user.
But, I am not sure how to do it including the avatar image link directly under the video where it shows the Avatar for the user that submitted the article and the text and link to user profile.

I need help with this code. Part of it is right where it just shows the users text name as a link (Posted by). But the user’s avatar link should be toggled also. Here is my code:


          <div style="padding: 0px 40px;" class="large justify">
          {user var=$user username=$video.username}
          {if $user}
          <a href="{$g_config.base_uri}/profile/{$video.username}/"><img src="{if $user.uri}{$user.uri}{else}{$g_config.template_uri}/images/media-avatar.jpg{/if}" alt="{$video.username}'s Profile" style="max-width: 50px; max-height: 38px; border: 1px solid black; display: inline-block; margin-right: 8px;" /></a>
          {/if}
          <span style="display: inline-block; vertical-align: top;">
            <div class="larger bold">{$video.title}</div>
            <div class="video-brief-date smallest normal">Posted
                {if $video.username}
                by
                {nocache}
                {if $g_logged_in}
                {/nocache}
                <a href="{$g_config.base_uri}/profile/{$video.username}/"><em>{$video.username}</em></a>
                {nocache}
                {else}
                <a href="http://www.site.net/user/login/" title="View User Profile"><em>{$video.username}</em></a>
                {/if}
                {/nocache}
                {/if} on {$video.date_added|t_datetime}.</div>
          </span>
          </div>

          <div style="padding: 0px 40px;" class="largest justify">{$video.description|rawhtml}</div>

          {if count($clips) > 1}
          <div id="clips">
            <b>Related Media Clips:</b><br />
            {foreach var=$clip from=$clips}
              <img src="{if $clip.thumbnail}{$clip.thumbnail}{else}{$g_config.no_preview}{/if}" href="{$clip.clip}" />
            {/foreach}
          </div>
          {/if}

          <br />

I am sorry I did not leave a link to the page in question. I guess that would help of course :slight_smile:
Also, I must say that I have very little knowledge in PHP. And I hope I posted in the right area. Any help would greatly be appreciated.

Here is the test page in question regarding the above mentioned code. As yo ucan see directly below the video, there is the Title of the article and the the information about date posted and by whom. The user link that posted it should goto the registration page. Along with the Avatar image next to the Title.

Then if you notice further down the page where a comment response has been made. The same will be done with those user links. So that if the user is not logged in those links will goto the registration page. And when they are logged in theywill goto the users profile page. Any help with this would be greatly appreciated. I know this is my first post but is has really been nagging me on how to fix this to make it right. Another question about this code, and I see this tag used a lot in php it seems, what is URI? As in $g_config.base_uri. I understand the $g_config.base_url, but the uri still evades me.

Thank you for any help that you may be able to offer. Or please let me know if I am not asking in the right area or asking improper questions. Thank you.

Are you using some kind of template system?

Anyway, I guess you want something like this (see the part in red):


          <div style="padding: 0px 40px;" class="large justify">
          {user var=$user username=$video.username}
          {if $user}
[B][COLOR="#FF0000"]                {if $g_logged_in}
                <a href="{$g_config.base_uri}/profile/{$video.username}/"><img src="{if $user.uri}{$user.uri}{else}{$g_config.template_uri}/images/media-avatar.jpg{/if}" alt="{$video.username}'s Profile" style="max-width: 50px; max-height: 38px; border: 1px solid black; display: inline-block; margin-right: 8px;" /></a>
                {else}
                <a href="http://www.site.net/user/login/"><img src="{if $user.uri}{$user.uri}{else}{$g_config.template_uri}/images/media-avatar.jpg{/if}" alt="{$video.username}'s Profile" style="max-width: 50px; max-height: 38px; border: 1px solid black; display: inline-block; margin-right: 8px;" /></a>
                {/if}[/COLOR][/B]
          {/if}
          <span style="display: inline-block; vertical-align: top;">
            <div class="larger bold">{$video.title}</div>
            <div class="video-brief-date smallest normal">Posted
                {if $video.username}
                by
                {nocache}
                {if $g_logged_in}
                {/nocache}
                <a href="{$g_config.base_uri}/profile/{$video.username}/"><em>{$video.username}</em></a>
                {nocache}
                {else}
                <a href="http://www.site.net/user/login/" title="View User Profile"><em>{$video.username}</em></a>
                {/if}
                {/nocache}
                {/if} on {$video.date_added|t_datetime}.</div>
          </span>
          </div>

          <div style="padding: 0px 40px;" class="largest justify">{$video.description|rawhtml}</div>

          {if count($clips) > 1}
          <div id="clips">
            <b>Related Media Clips:</b><br />
            {foreach var=$clip from=$clips}
              <img src="{if $clip.thumbnail}{$clip.thumbnail}{else}{$g_config.no_preview}{/if}" href="{$clip.clip}" />
            {/foreach}
          </div>
          {/if}

          <br />

You’ll have to test it though.
And I have no idea what those {nocache} and {/nocache} are needed for, you might need to add some of those too, who knows :slight_smile:

Thanks for your help.

Yes, I am using a server script that uses .tpl files for all the pages. There is an editor for them all in the admin area.

I have replaced it with your code. It works, but, now it doesn’t show the user profile image. There is an image specified for default, yet it does not show.
I have tried a couple different changes to try and get it to work including the nocache tags. But still nothing.

This is code I have now. The code you gave has the same effect:

{user var=$user username=$video.username}
          {if $user}
                <nocache>
                {if $g_logged_in}
                </nocache>
                <a href="{$g_config.base_uri}/profile/{$video.username}/"><img src="{if $user.uri}{$user.uri}{else}{$g_config.template_uri}/images/media-avatar.jpg{/if}" alt="{$video.username}'s Profile" style="max-width: 50px; max-height: 38px; border: 1px solid black; display: inline-block; margin-right: 8px;" /></a>
                <nocache>
                {else}
                <a href="http://www.unexplainedmedia.net/user/login/"><img src="{if $user.uri}{$user.uri}{else}{$g_config.template_uri}/images/media-avatar.jpg{/if}" alt="{$video.username}'s Profile" style="max-width: 50px; max-height: 38px; border: 1px solid black; display: inline-block; margin-right: 8px;" /></a>
                {/if}
                </nocache>
          {/if}

Still stumped. I have a couple different user vars to work with. $user.name is the users Name. $video.username is the user login name that uploaded the associated article. $user.uri is the specified avatar image for the user {if} one is provided. If not it should use the default. Yet it shows no image.

Thank you so much for your help!

I don’t think it’s a problem with the script. The link to the avatar is

http://www.unexplainedmedia.net/templates/UM-Custom/images/media-avatar.jpg

and it seems that image is missing?

Hmm … Yes it does seem that the image is missing. Which is weird since it was working previously. Which is why I did not check that. Thanks you! … I’m looking into it and will let you know.

Have it fixed! Thank you so much for your help! … What stumped me from the beginning was the unknown of being able to use more than one {if} inside each other.

Now I have to try and implement this with the user comments area.