Willkommen, Gast
Benutzername: Passwort: Angemeldet bleiben:

THEMA: Link 2 user profile from article view - How?

Link 2 user profile from article view - How? 7 Jahre 6 Monate her #487

  • cheeseus
  • cheeseuss Avatar
  • OFFLINE
  • Fresh Boarder
  • Beiträge: 6
  • Dank erhalten: 1
  • Karma: 0
Hello,

The main reason for me to look for a plugin/component that shows the user profile in the frontend is to be able to link the Author Name (displayed under the article in Article View) to the profile page displayed by your component.

The link to the profile page in the user list looks like this:
<a href="'.JRoute::_("index.php?option=com_userprofile&view=userprofile&id=".$row->id."%3A".$row->username). '">
that is, you also pass the username with the userid. The username is the problem - in Article View you cannot get the username, only the user's real name and their ID.

The only solution that I can think of is to somehow write the author's username in the "created_by_alias" field in the "com_content" table, but this field is empty. I don't know why it is empty. I have tried looking for the code that inserts the author's alias in the "com_content" table but didn't find anything.

Anyway, this isn't a very solid solution.

Perhaps you can help me modify your code in such a way that the username is no longer required in order to display the user profile.

Currently, when I link the author's name from Article View to the profile page like this:
JHTML::_('link',JRoute::_('index.php?option=com_userprofile&view=userprofile&id='.$this->item->created_by),$author)
I see two error notices:
Notice: Trying to get property of non-object in ...\components\com_userprofile\models\userprofile.php on line 156
and
Notice: Trying to get property of non-object in ...\components\com_userprofile\models\userprofile.php on line 244
The user profile page does show (with the above errors) but instead of the user's real name, their username is displayed (when accessed from the user list, the real name shows), and the articles written by this user are not displayed either.

Hope you can help!
Letzte Änderung: 7 Jahre 6 Monate her von cheeseus.

Link 2 user profile from article view - How? 7 Jahre 6 Monate her #488

  • cheeseus
  • cheeseuss Avatar
  • OFFLINE
  • Fresh Boarder
  • Beiträge: 6
  • Dank erhalten: 1
  • Karma: 0
Some progress... The problem isn't in the username. I tried editing the href in the user list to: index.php?option=com_userprofile&view=userprofile&id=".$row->id, removing the ."%3A".$row->username part. And the profile page loads without any errors.

But when I try doing the same from Article View, I get the above two errors which have something to do with this line:
$params = new JParameter($menu->params);
which appears twice - in function GetUserDetails($id) and in private function GetUserPosts($id).

Still, I can't find a solution to the problem...

Link 2 user profile from article view - How? 7 Jahre 6 Monate her #489

  • cheeseus
  • cheeseuss Avatar
  • OFFLINE
  • Fresh Boarder
  • Beiträge: 6
  • Dank erhalten: 1
  • Karma: 0
Sorted!

The problem occurred because the new currently active page parameter was not being passed to the above part of the code.

My solution is pretty simple but not flexible: I've hard-coded the Itemid of the target page (the new active page) in the HREF:
<?php echo JText::sprintf('COM_CONTENT_WRITTEN_BY' , JHTML::_('link',JRoute::_('index.php?option=com_userprofile&view=userprofile&id='.$author_id."&Itemid=260"),$author)); ?>
		<!-- Manual feed of the new active menu item is required above as otherwise an error is triggerred -->
Letzte Änderung: 7 Jahre 6 Monate her von cheeseus.

Link 2 user profile from article view - How? 7 Jahre 6 Monate her #490

  • Jonny132
  • Jonny132s Avatar
  • OFFLINE
  • Administrator
  • Beiträge: 151
  • Dank erhalten: 3
  • Karma: 4
Hello cheeseus,

I guess, that the problem is, that you don't have enabled SEO-Friendly Urls. As you figured out you have to add the Itemid. I'm not sure, if I can solve this problem, because the Itemid points to the active menu. So what if you have two menuitems with the type com_userprofile? How can I figure it out in my code to which menuitem you want to relate?

I definitely will search for a solution, but I'm not sure if there is a solution.

Till then, I wish you a nice weekend ;)

Thanks

Link 2 user profile from article view - How? 7 Jahre 6 Monate her #492

  • cheeseus
  • cheeseuss Avatar
  • OFFLINE
  • Fresh Boarder
  • Beiträge: 6
  • Dank erhalten: 1
  • Karma: 0
Hi Johnny,

It doesn't matter if SEO-friendly URLs (and/or MOD_REWRITE) are enabled or not - this only concerns the appearance of the URL in the address bar and the server's ability to "understand" SEO-friendly addresses and "translate" them to "normal" so that it knows what to do.

Even with SEO-friendly addresses ON, you still need to pass the "new currently active page Itemid" to your script in order for it to work correctly (compare the URL in the address bar and the actual URL in the status bar). I have just tested all possible options, and if I remove the hard-coded Itemid, the error persists.

So, in conclusion, if someone wants to use your component by linking an author's name (from somewhere not in your authors list) to their profile, they will have to hard-code the Itemid in their code.

Unfortunately, this means that you will need to work out a solution if you want your component to work seamlessly with the rest of the Joomla site.

Thanks for replying and good luck!

Link 2 user profile from article view - How? 7 Jahre 6 Monate her #494

  • Jonny132
  • Jonny132s Avatar
  • OFFLINE
  • Administrator
  • Beiträge: 151
  • Dank erhalten: 3
  • Karma: 4
Hi again,

i know what seo-friendly urls are ;) but yes... it solves the problem (for my component)...

Just look at http://tuts4you.de/autoren/42-Jonny132. As you see, the second section of the url represents the menu and there is no problem with linking.

The problem is, that you not really understood my answer... It's not a problem IN the component. The component knows what's the active menu.
Your problem is that you are using my component in a different context (article view) where i'm not able to know to which menuitem you are refering to.

Maybe my answer was not good articulated ;)

Edit: I also tried to call a non-SEO-Url, and as you can see, even if seo is activated AND the active Itemid is not in the url, it works:
http://tuts4you.de/?option=com_userprofile&view=userprofile&id=42
Letzte Änderung: 7 Jahre 6 Monate her von Jonny132.
Ladezeit der Seite: 0.272 Sekunden