Hello,
has anybody managed to link from an album/photo to the user profil?
I tried to include a link in photo.tpl that points to the user profil. I can't
acces Drupals uid in embedded Gallery.
I know that the externalId/uid is stored in a table called g3_ExternalIdMap,
but how can I acces this table from photo.tpl?

Thanks in advance,

Marco

Comments

profix898’s picture

Its quite easy to achieve what you want. Open the theme.inc file of your theme. If you need an additional variable for a photo page, search for the 'showPhotoPage(&$template, $item, $params) { ... }' function. As the $user object of Drupal is a global variable you can easily access it directly (even outside Drupal, e.g. in G2). You can now get and modify all available theme variables using $theme =& $template->getVariableByReference('theme');. In case you need a new template variable 'drupaluser' containing the Drupal username then you would use the following code:

<?php
function showPhotoPage(&$template, $item, $params) {
	$dataTypes = array('owner', 'parents', 'systemLinks', 'itemLinks', 'permissions',
			   'itemLinksDetailed', 'itemNavigator', 'imageViews');
	if (!empty($params['showMicroThumbs'])) {
	    $dataTypes[] = 'navThumbnails';
	}
	$ret = $this->loadCommonTemplateData($template, $item, $params, $dataTypes);
	if ($ret) {
	    return array($ret, null);
	}
	
        // -- begin: add this -- //
	global $user;
	$theme =& $template->getVariableByReference('theme');
	$theme['drupaluser'] = $user->name;
        // -- end: add this -- //

	return array(null, 'theme.tpl');
    }
?>

In your .tpl file you can then access the 'drupaluser' variable like any other predefined variable. If you e.g. want to welcome the user with its Drupal username, you would add the following line to your template Welcome {$theme.drupaluser}!.

Hope you can follow this short tutorial. Let me know if you need further assistance.

macco’s picture

Thanks,
you put me on the right track.
But I wanted the Drupal ID from the owner of the photo to link to the owners profil.
I apologize for my incomprehensible writing
I did this way now:


function showPhotoPage(&$template, $item, $params) {
	$dataTypes = array('owner', 'parents', 'systemLinks', 'itemLinks', 'permissions',
			   'itemLinksDetailed', 'itemNavigator', 'imageViews');
	if (!empty($params['showMicroThumbs'])) {
	    $dataTypes[] = 'navThumbnails';
	}
	$ret = $this->loadCommonTemplateData($template, $item, $params, $dataTypes);
	if ($ret) {
	    return array($ret, null);
	}		 

        // -- begin: add this -- //	
    
          global $gallery;
	$theme =& $template->getVariableByReference('theme');    
	$query = "SELECT g_externalId  FROM g2_ExternalIdMap WHERE g_entityId
='".$theme['item']['owner']['id']."' AND g_entityType='GalleryUser'";
	$results = $gallery->search($query);
   	$drupaluserId = $results[1]->nextResult();
	$theme['drupaluserId'] = $drupaluserId[0];

    // -- end: add this -- //

	return array(null, 'theme.tpl');
    }

I think your tutorial will help me in the future.

By the way, is there a way to use Drupal functions in Gallery2?

Danke,
Marco

macco’s picture

Status: Active » Fixed

I close this issue.
Thanks again to profix898.

Regard,
Marco

scott summers’s picture

Sorry i didn't work for me. i tried both the patches but neither $theme['drupaluser'] nor $theme['drupaluserId'] could be accessed in my modules/core/templates/blocks/local/ItemInfo.tpl file. It seems that im missing something.

macco’s picture

Status: Fixed » Active

Hi,
it seems to me that you placed the code at a wrong location.

In theme.inc should be a part for modules, something like this:

 /**
     * @see GalleryTheme::showModulePage
     */
    function showModulePage(&$template, $item, $params, $templateFile) {
	$ret = $this->loadCommonTemplateData(
	    $template, $item, $params, array('parents', 'systemLinks'));
	if ($ret) {
	    return array($ret, null);
	}
	
           // -- begin: add this -- //    
    
          global $gallery;
          $theme =& $template->getVariableByReference('theme');    
          $query = "SELECT g_externalId  FROM g2_ExternalIdMap WHERE g_entityId
          ='".$theme['item']['owner']['id']."' AND g_entityType='GalleryUser'";
          $results = $gallery->search($query);
          $drupaluserId = $results[1]->nextResult();
          $theme['drupaluserId'] = $drupaluserId[0];

          // -- end: add this -- //

	return array(null, 'theme.tpl');
    }

If this doesn't help, please post exactly what you have done including your code.

Marco

scott summers’s picture

Hi macco,
I've added the following code at location: www.mysite.com/gallery2/themes/matrix/theme.inc file.
I tried to use it in modules/core/templates/blocks/local/ItemInfo.tpl file the same way profix898 has suggested i.e. Welcome {$theme.drupaluser}!. but outputs only Welcome !.

function showPhotoPage(&$template, $item, $params) {
	$dataTypes = array('owner', 'parents', 'systemLinks', 'itemLinks', 'permissions',
			   'itemLinksDetailed', 'itemNavigator', 'imageViews');
	if (!empty($params['showMicroThumbs'])) {
	    $dataTypes[] = 'navThumbnails';
	}
	$ret = $this->loadCommonTemplateData($template, $item, $params, $dataTypes);
	if ($ret) {
	    return array($ret->wrap(__FILE__, __LINE__), null);
	}
        // -- begin: add this -- //
          global $gallery;
    $theme =& $template->getVariableByReference('theme');   
    $query = "SELECT g_externalId  FROM g2_ExternalIdMap WHERE g_entityId='".$theme['item']['owner']['id']."' AND g_entityType='GalleryUser'";
    $results = $gallery->search($query);
       $drupaluserId = $results[1]->nextResult();
    $theme['drupaluserId'] = $drupaluserId[0];
        // -- end: add this -- //

	return array(null, 'theme.tpl');
}

Thanks for your kind help.
im new to drupal but appreciate the way people on drupal help others. thanks to drupal and all drupal guys.

I.X.

scott summers’s picture

sorry i forgot this to ask. i have heard about contact owner module for gallery. but could not find it. could you please tell me the url or where to find this module for gallery 2.1. i shall be very thankful.

macco’s picture

Sorry don't know about blocks.
But you have the function that gives the information to ItemInfo.tpl. That is not theme.inc I guess it should be somewhere in modules/core, I am afraid you have to search a bit.

profix898’s picture

i have heard about contact owner module for gallery. but could not find it

Take a look at the user contributed modules (http://codex.gallery2.org/Gallery2:User_Contributions) the contact owner module is listed there as well ...

I've added the following code at location: www.mysite.com/gallery2/themes/matrix/theme.inc file.
I tried to use it in modules/core/templates/blocks/local/ItemInfo.tpl file the same way profix898 has suggested i.e. Welcome {$theme.drupaluser}!. but outputs only Welcome !.

Its a little more difficult in your case. Blocks are reusable templates that are embedded into other (photo/album) templates. Without telling you too much details, this is what you need to make it work ...

Make the modification to theme.inc as described above (and as you have already tried). Then open photo.tpl (in the templates folder of your theme, e.g. matrix/templates/photo.tpl) and search for a snippet like this: {g->block type="core.ItemInfo" ... }. That's the code which includes the block template, in this case the 'core.ItemInfo' block. The template is located at modules/core/templates/blocks/ItemInfo.tpl. You must somehow pass the data into your blocks template now and thats what was missing in your attempts to get this working, I guess. The easiest way to achieve this is to add an additional element to the parameter list, that is passed to the block. You can then access this parameter in your block template.

Not sure you was able to follow me through the above paragraph!? If not, forget about the theory and take a look at the actual code. Here are the modifications needed to make this work:

1. /themes/matrix/theme.inc:
Take the code as posted above. No further modifications needed.

2. /themes/matrix/templates/photo.tpl:
In this file you search for a section that starts like {g->block type="core.ItemInfo" ... } and change it to this

<td style="width: 30%">
  {g->block type="core.ItemInfo"
            item=$theme.item
            showDate=true
            showOwner=$theme.params.showImageOwner
            class="giInfo"
            drupaluser=$theme.drupaluser} // This passes $theme.drupaluser to ItemInfo.tpl as 'drupaluser'
  {g->block type="core.PhotoSizes" class="giInfo"}
</td>

3. /modules/core/templates/blocks/ItemInfo.tpl
You can now use the new variable like this Welcome {$drupaluser}! in your block template.

To sum up: You first introduce a new theme variable in theme.inc, that will be available for all theme templates such as photo.tpl. You then pass the variable into you block template (ItemInfo.tpl) by adding it to the parameter list of the {g->block ... } call.

As blocks are reusable in several locations, you will notice that the variable will not be available in every case. You will need to modify album.tpl in addition to photo.tpl to make it available for the block on album pages. For this you must search album.tpl for the code that includes the block and add the parameter there as well.
I also suggest that you wrap your code in ItemInfo.tpl like this

{if !empty($drupaluser)}
  Welcome {$drupaluser}!
{/if}

to make sure it is only displayed when the variable is actually set.

Hope you got it. Let me know if you need additional help.

scott summers’s picture

Status: Active » Fixed

GREAT!!!! profix898, it worked very well for me. Many Thanks again.

Sorry for such a long delay. Actually i was off for days.

Anyway once again many thanks to you and macco for your assistance on this issue. Following your instructions i have also made the username with each thumbnail to link user's drupal profile.

I'm posting the code below if it can be helpful to other users.

ALBUM PAGE CODE

    /**
     * @see GalleryTheme::showAlbumPage
     */
    function showAlbumPage(&$template, $item, $params, $childIds) {
	$ret = $this->loadCommonTemplateData(
	    $template, $item, $params,
	    array('owner', 'viewCount', 'childCount', 'descendentCount', 'parents',
		  'systemLinks', 'itemLinks', 'itemSummaries', 'permissions',
		  'thumbnails', 'pageNavigator', 'jumpRange'),
	     $childIds);
	if ($ret) {
	    return array($ret->wrap(__FILE__, __LINE__), null);
	}

    global $user;    
	if($user->uid) {
			// -- begin: add this -- //
			  global $gallery;
		$theme =& $template->getVariableByReference('theme');
		// drupal id of the album owner
		$query = "SELECT g_externalId FROM g2_ExternalIdMap WHERE g_entityId='".$theme['item']['owner']['id']."' AND g_entityType='GalleryUser'";
		$results = $gallery->search($query);
		$drupalId = $results[1]->nextResult();
		$theme['drupaluserId'] = $drupalId[0];
		
		// drupal ids for each thumbnail
		$count_thumbnails = $theme['item']['childCount'];
		$thumb_ids = '(';
		for($i=0;$i<$count_thumbnails;$i++) {
			if(!empty($theme['children'][$i]['ownerId']))
				$thumb_ids .= $theme['children'][$i]['ownerId'].',';
			else break;	
		}
		$thumb_ids = substr($thumb_ids,0,-1).')';
		$query = "SELECT g_externalId, g_entityId FROM g2_ExternalIdMap WHERE g_entityId IN ".$thumb_ids." AND g_entityType='GalleryUser'";
		$result = mysql_query($query);
		while($row = mysql_fetch_object($result)) {
			$theme['drupalId_thmb'][$row->g_entityId] = $row->g_externalId;
		}
			// -- end: add this -- //
	}
	
	return array(null, 'theme.tpl');
    }

PHOTO PAGE CODE

    /**
     * @see GalleryTheme::showPhotoPage
     */
    function showPhotoPage(&$template, $item, $params) {
	$dataTypes = array('owner', 'parents', 'systemLinks', 'itemLinks', 'permissions',
			   'itemLinksDetailed', 'itemNavigator', 'imageViews');
	if (!empty($params['showMicroThumbs'])) {
	    $dataTypes[] = 'navThumbnails';
	}
	$ret = $this->loadCommonTemplateData($template, $item, $params, $dataTypes);
	if ($ret) {
	    return array($ret->wrap(__FILE__, __LINE__), null);
	}
	
    global $user;    
	if($user->uid) {
        // -- begin: add this -- //
          global $gallery;
		$theme =& $template->getVariableByReference('theme');  
		$query = "SELECT g_externalId  FROM g2_ExternalIdMap WHERE g_entityId='".$theme['item']['owner']['id']."' AND g_entityType='GalleryUser'";
		$results = $gallery->search($query);
		$drupalId = $results[1]->nextResult();
		$theme['drupaluserId'] = $drupalId[0];
        // -- end: add this -- //
	}	

	return array(null, 'theme.tpl');
    }

Once agian Thanks for your help.

I.X.

yngens’s picture

subscribe

Anonymous’s picture

Status: Fixed » Closed (fixed)
plan9’s picture

Component: User interface / Theming » Miscellaneous

Does this method still work with the latest version of gallery 2.3?
I'm using Ice theme.

Thanks for any info

G

plan9’s picture

Title: Link from Gallery2 photo to Drupal User Profil » Link from Gallery2 photo to Drupal User Profile
Status: Closed (fixed) » Active

I've also tried the above with Matrix and it still doesn't work. I'm assuming therefore that the above method is incompatible with gallery 2.3

Can anyone else please verify?

Thanks

G

plan9’s picture

Any chance of an update for gallery 2.3 please?

plan9’s picture

Hello...

Anyone....?

plan9’s picture

Status: Active » Closed (fixed)

Closing this issues as gallery module is now dead