[info module] How to link photo owner to profile page?

skunker

Joined: 2005-02-04
Posts: 344
Posted: Sat, 2012-04-14 00:01

Hi all,
On the default G3 info module you can see the username of the person that uploaded the photo (see attached for screenshot). I am wondering how/if it's possible to link the username (ie "historykid") to his user profile page? I am guessing there will be some php code involved ? Any other ideas? Thanks.

AttachmentSize
info.png11.93 KB
 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Sat, 2012-04-14 17:12

If the user sets the url in their profile when they/admin set up the user then it will be a link to that url.

you could edit the info_block.php file to add:
user_profile::url($user->id)
that should get the profile page.

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

 
skunker

Joined: 2005-02-04
Posts: 344
Posted: Sat, 2012-04-14 20:19

Thanks Dave, will give that a shot.

 
skunker

Joined: 2005-02-04
Posts: 344
Posted: Sun, 2012-04-15 01:57

Well Dave, I tried to play around with it for an hour and couldn't quite get it to display correctly. Here's the block code:

if ($theme->item->owner && module::get_var("info", "show_owner")) {
$display_name = $theme->item->owner->display_name();
if ($theme->item->owner->url) {
$info["owner"] = array(
"label" => t("Owner:"),
"value" => user_profile::url($user->id) .
html::clean($display_name) . "</a>"
);

The bold part is what I've been messing with (did not include the Bold tag in the code). Two things: 1.) How do I correctly write it so it will display a hyperlink? 2.) I can't figure out the $user variable to have it print the user ID # instead of the user name. The way it is written now (as shown) outputs the username, but not the ID. I studied the way the COMMENTS BLOCK handled the user profile links and it showed it as $author_id so I'm wondering if perhaps it's $user_id .

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Tue, 2012-04-17 02:46

I'm a bit confused as to what you are after.
I understand you want a link to the user profile page but why? If it is a link and the user is not that user they will get a 404/permissions/dang page.

In your example if I visit and I click on the historykid link I would get a 404/permissions/dang page.

I need a better user story to understand what you are after.

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

 
skunker

Joined: 2005-02-04
Posts: 344
Posted: Tue, 2012-04-17 13:12

Dave,
Thank you for responding. All I am trying to do is have a "Uploaded by: John" link that, when is clicked, it will take the visitor to the uploader's profile page. That's why I was wondering if we could customize the info module so instead of having the URL link, it would go to the user's profile page. I don't know why you said "If it is a link and the user is not that user they will get a 404/permissions/dang page" because if I click the "historykid" profile link from the RECENT COMMENTS block, I am able to go to the historykid profile page and see his profile. I want to use that same functionality in the info module and direct the visitor to historykid's profile page.

Does that make sense?

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Tue, 2012-04-17 23:10
Quote:
I am able to go to the historykid profile page and see his profile.

as a guest? I bet it is because you are admin?
I might be missing something here as I don't use the info module or the comment module/block that but but is the user's profile page only advisable to the user only?
Needing a link to understand now is better that your user story.
here is what I did to get a modal window to pop up to contact the item owner.

class info_block_Core {
  static function get_site_list() {
    return array("metadata" => t("Metadata"));
  }

  static function get($block_id, $theme) {
    $block = "";
    switch ($block_id) {
    case "metadata":
      if ($theme->item()) {
        $block = new Block();
        $block->css_id = "g-metadata";
        $block->title = $theme->item()->is_album() ? t("Album info") : t("Photo info");
        $block->content = new View("info_block.html");
        if ($theme->item->title && module::get_var("info", "show_title")) {
          $info["title"] = array(
            "label" => t("Title:"),
            "value" => html::purify($theme->item->title)
          );
        }
        if ($theme->item->description && module::get_var("info", "show_description")) {
          $info["description"] = array(
            "label" => t("Description:"),
            "value" => nl2br(html::purify($theme->item->description))
          );
        }
        if (!$theme->item->is_album() && module::get_var("info", "show_name")) {
          $info["file_name"] = array(
            "label" => t("File name:"),
            "value" => html::clean($theme->item->name)
          );
        }
        if ($theme->item->captured && module::get_var("info", "show_captured")) {
          $info["captured"] = array(
            "label" => t("Captured:"),
            "value" => gallery::date_time($theme->item->captured)
          );
        }
        if ($theme->item->owner && module::get_var("info", "show_owner")) {
          $display_name = $theme->item->owner->display_name();
          if ($theme->item->owner->url) {
            $info["owner"] = array(
              "label" => t("Owner:"),
              "value" => "<a href=\"{$theme->item->owner->url}\">" .
                         html::clean($display_name) . "</a>"
            );
          } else {
			$user_profile_url = url::site("user_profile/contact/{$theme->item->owner->id}");
            $info["owner"] = array(
              "label" => t("Owner:"),
              "value" => "<a class=\"g-dialog-link\" href=\"{$user_profile_url}\">" .
                         html::clean($display_name) . "</a>"
            );
          }
        }
        $block->content->metadata = $info;

        module::event("info_block_get_metadata", $block, $theme->item);
      }
      break;
    }
    return $block;
  }
}

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Wed, 2012-04-18 01:31

OK I get it now. A logged in user can view the profile. Guests will still get a 404.

class info_block_Core {
  static function get_site_list() {
    return array("metadata" => t("Metadata"));
  }

  static function get($block_id, $theme) {
    $block = "";
    switch ($block_id) {
    case "metadata":
      if ($theme->item()) {
        $block = new Block();
        $block->css_id = "g-metadata";
        $block->title = $theme->item()->is_album() ? t("Album info") : t("Photo info");
        $block->content = new View("info_block.html");
        if ($theme->item->title && module::get_var("info", "show_title")) {
          $info["title"] = array(
            "label" => t("Title:"),
            "value" => html::purify($theme->item->title)
          );
        }
        if ($theme->item->description && module::get_var("info", "show_description")) {
          $info["description"] = array(
            "label" => t("Description:"),
            "value" => nl2br(html::purify($theme->item->description))
          );
        }
        if (!$theme->item->is_album() && module::get_var("info", "show_name")) {
          $info["file_name"] = array(
            "label" => t("File name:"),
            "value" => html::clean($theme->item->name)
          );
        }
        if ($theme->item->captured && module::get_var("info", "show_captured")) {
          $info["captured"] = array(
            "label" => t("Captured:"),
            "value" => gallery::date_time($theme->item->captured)
          );
        }
        if ($theme->item->owner && module::get_var("info", "show_owner")) {
          $display_name = $theme->item->owner->display_name();
          if ($theme->item->owner->url) {
            $info["owner"] = array(
              "label" => t("Owner:"),
              "value" => "<a href=\"{$theme->item->owner->url}\">" .
                         html::clean($display_name) . "</a>"
            );
          } else {
			$user_profile_url = url::site("user_profile/show/{$theme->item->owner->id}");
            $info["owner"] = array(
              "label" => t("Owner:"),
              "value" => "<a href=\"{$user_profile_url}\">" .
                         html::clean($display_name) . "</a>"
            );
          }
        }
        $block->content->metadata = $info;

        module::event("info_block_get_metadata", $block, $theme->item);
      }
      break;
    }
    return $block;
  }
}

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

 
skunker

Joined: 2005-02-04
Posts: 344
Posted: Wed, 2012-04-18 02:09

Wow, Dave. Thanks! Where do I paste that? Do I erase the code in the info_block.php file and replace it with what you wrote?

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Wed, 2012-04-18 03:39

That is the whole info_block.php file

don't forget the first 19 or so lines.

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

 
skunker

Joined: 2005-02-04
Posts: 344
Posted: Wed, 2012-04-18 19:15

Thanks, Dave. That worked well. Now I just need to work on customizing the 404 page so the guest can register and view the profile.

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Thu, 2012-04-19 01:33

gallery/modules/views/error_404.html.php

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team