Page 1 of 2

CGBlogs dynamic Gravatars

Posted: Thu Nov 29, 2012 9:27 pm
by erajis
He team, I'm trying to add a gravatar to CGBlog that pulls from the admin/editors email. We have seven authors, and I'd like to add their avatar dynamically.

Here's what I've put in the smarty template:
{gravatar width=80 height=80 email='$author_email'}

I still can't get the email string to populate, any help would be appreciated.

Thanks team,
Emeka Rajis

Re: CGBlogs dynamic Gravatars

Posted: Thu Nov 29, 2012 10:00 pm
by Jo Morg
I believe you can use {gravatar width=80 height=80 email=$author_email}...

Re: CGBlogs dynamic Gravatars

Posted: Thu Nov 29, 2012 10:04 pm
by erajis
Still doesn't work for me :( Here's my template code:

CGBLOG SUMMARY TEMPLATE:
//////////////////////////////////////////////////
...
{if $entry->author}
<div class="CGBlogSummaryAuthor">
{gravatar width=80 height=80 email=$author_email} {$author_label} {authorname username=$entry->author}
</div>
{/if}
...
//////////////////////////////////////////////////

Re: CGBlogs dynamic Gravatars

Posted: Thu Nov 29, 2012 10:06 pm
by manuel
Dear Erajis,

Smarty will only recognize vars if you enclose them in double quotes
http://www.smarty.net/docsv2/en/languag ... thor_email"[/code]
Greetings,
Manuel

Re: CGBlogs dynamic Gravatars

Posted: Thu Nov 29, 2012 10:24 pm
by Jo Morg
manuel wrote:...Smarty will only recognize vars if you enclose them in double quotes...
http://www.smarty.net/docsv2/en/languag ... thor_email"[/code]
Actually, that is incorrect. Otherwise this wouldn't be possible:

Code: Select all

{assign var=running_total value=$running_total+$some_array[$row].some_value}
And it is possible.
http://www.smarty.net/docs/en/language. ... assign.tpl.
However email="$author_email" will evaluate the variable while email='$author_email' won't. ;) So manuel's code should also work.
In any case I would check if {$author_email} actually holds a valid email...

Re: CGBlogs dynamic Gravatars

Posted: Thu Nov 29, 2012 11:29 pm
by manuel
Dear Jo Morg,

Oops, you are absolutely right :)
That's one "only" too much in my previous response

Erajis, please check the content of the var with:

Code: Select all

{$author_email|@debug_print_var}
Greetings,
Manuel

Re: CGBlogs dynamic Gravatars

Posted: Fri Nov 30, 2012 12:10 am
by Jo Morg
manuel wrote:Oops, you are absolutely right :)
That's one "only" too much in my previous response
;)

Re: CGBlogs dynamic Gravatars

Posted: Fri Nov 30, 2012 3:07 am
by erajis
Hey guys, the logic returned "Null" :

...
{if $entry->author}
<div class="CGBlogSummaryAuthor">
{$author_email|@debug_print_var}
{gravatar width=80 height=80 email="$author_email"} {$author_label} {authorname username=$entry->author}
</div>
{/if}
...
and my admin account has an email attached to it, so I'm not sure what the issue is...

Thanks guys for your help!

Re: CGBlogs dynamic Gravatars

Posted: Fri Nov 30, 2012 12:16 pm
by Jo Morg
Well... that's why http://forum.cmsmadesimple.org/viewtopi ... =40&t=2661 should be read 1st...
Where does $author_email come from? How do you generate this variable value?
There must be something wrong before the parser even gets to the sample code you actually provided.

Re: CGBlogs dynamic Gravatars

Posted: Fri Nov 30, 2012 5:45 pm
by erajis
Jo Morg wrote:Well... that's why http://forum.cmsmadesimple.org/viewtopi ... =40&t=2661 should be read 1st...
Where does $author_email come from? How do you generate this variable value?
There must be something wrong before the parser even gets to the sample code you actually provided.
I'm not a php, or smarty guru - so I'm not sure how to generate the value. I thought it would be as simple as {gravatar email='$author_email'}, but to no avail. I'm using the latest version of cms 1.11.3, and the latest version of CGBlog 1.9.8. -- Moreover I'm not sure how the parser works or how to evaluate it. I am making strides to learn more about smarty, and php. But this gravatar issue seems so close but yet so far! Thanks for your help, I tried to look around first before I bothered you guys about it.

-- Any help would be appreciated.

Here's my summary template:

Code: Select all

<!-- Start CGBlog Display Template -->
{if isset($error)}{cgerror}{$error}{/cgerror}{/if}

{if $pagecount > 1}
  <p>
{if $pagenumber > 1}
{$firstpage}&nbsp;{$prevpage}&nbsp;
{/if}
{$pagetext}&nbsp;{$pagenumber}&nbsp;{$oftext}&nbsp;{$pagecount}
{if $pagenumber < $pagecount}
&nbsp;{$nextpage}&nbsp;{$lastpage}
{/if}
</p>
{/if}
{foreach from=$items item=entry}
<div class="CGBlogSummary">

{if $entry->postdate}
	<div class="CGBlogSummaryPostdate">
		{$entry->postdate|cms_date_format}
	</div>
{/if}

<div class="CGBlogSummaryLink">
<a href="{$entry->detail_url}" title="{$entry->title|escape:htmlall}">{$entry->title|escape}</a>
</div>

{if $entry->categories}
<div class="CGBlogSummaryCategory">
{strip}{$category_label}
 {foreach from=$entry->categories item='category'}
   {$category.name}&nbsp;
 {/foreach}
{/strip}
</div>
{/if}

{if $entry->author}
	<div class="CGBlogSummaryAuthor">
{gravatar width=80 height=80 email="$author_email"} {$author_label} {authorname username=$entry->author}
	</div>
{/if}
 

{if $entry->summary}
	<div class="CGBlogSummarySummary">
		{eval var=$entry->summary}
	</div>

{else if $entry->content}

	<div class="CGBlogSummaryContent">
		{eval var=$entry->content}
	</div>
{/if}

{if isset($entry->extra)}
    <div class="CGBlogSummaryExtra">
        {eval var=$entry->extra}
	{* {cms_module module='Uploads' mode='simpleurl' upload_id=$entry->extravalue} *}
    </div>
{/if}
{if isset($entry->fields)}
  {foreach from=$entry->fields item='field'}
     <div class="CGBlogSummaryField">
        {if $field->type == 'file'}
          <img src="{$entry->file_location}/{$field->value}"/>
        {else}
          {$field->name}:&nbsp;{eval var=$field->value}
        {/if}
     </div>
  {/foreach}
{/if}

</div>
{/foreach}
<!-- End CGBlog Display Template -->
ER

Re: CGBlogs dynamic Gravatars

Posted: Fri Nov 30, 2012 6:38 pm
by Jo Morg
Well, no need to be a Smarty guru, nor (not by a long shot) a PHP guru. :).
Most of the webdesign made with CMSMS requires a basic knowledge of Smarty which is very easy.
But we can't assume that some variable is available on a certain template, just because... well, because!
CMSMS core and Modules assign values/arrays/objects to Smarty variables in order for the designer to use and manipulate at will.
It's generically documented on most cases.

That being said, try

Code: Select all

{get_template_vars}
to see what variables you have available on a certain template. And after that if you want to further inspect what a certain variable holds use manuel's tip: @debug_print_var. If a certain variable doesn't exist, you may consider searching DOCs and this forum (chances are someone already found a solution). :)
And by then, you will probably know what kind of help you actually need and how to ask for it.

Re: CGBlogs dynamic Gravatars

Posted: Fri Nov 30, 2012 6:44 pm
by erajis
Thank you so much, I'm hot on the chase! I'll report back once I have this solved! Thanks again for your patience!

ER

Re: CGBlogs dynamic Gravatars

Posted: Sat Dec 01, 2012 12:03 am
by erajis
Okay so I'm hot on the trail. I'm trying to call the string from the database in a UDT called "getemail".

Code: Select all

global $gCms;
$db =& $gCms->GetDb(); 

$email = isset($params['email']) ? $params['email'] : "";
$feu_field = isset($params['feufield']) ? $params['feufield'] : ""; 

$query = "SELECT email FROM ".cms_db_prefix()."users WHERE email=?";
$row = $db->GetRow($query, array($user_name)); 
if($row){   
 $result = $row['email'];
}else{  
if($gCms->modules['FrontEndUsers']['object'] && !empty($feu_field)) 
{    
 $query = "SELECT id FROM ".cms_db_prefix()."module_feusers_users WHERE email=?";   
$feid = $db->GetOne($query, array($email));    
if($feid)   {   

$query = "SELECT data FROM ".cms_db_prefix()."module_feusers_properties WHERE email=? AND title=?";   
$result = $db->GetOne($query, array($feid,$feu_field));      
}    
}
} 
if(!$result){   

$result = "Username: $email doesn't exist or feufield is not set";} 
return $result;
In my template I'm inserting it as:

Code: Select all

{get_template_vars}
{$author_email|@debug_print_var}
<!-- Start CGBlog Display Template -->
{if isset($error)}{cgerror}{$error}{/cgerror}{/if}

{if $pagecount > 1}
  <p>
{if $pagenumber > 1}
{$firstpage}&nbsp;{$prevpage}&nbsp;
{/if}
{$pagetext}&nbsp;{$pagenumber}&nbsp;{$oftext}&nbsp;{$pagecount}
{if $pagenumber < $pagecount}
&nbsp;{$nextpage}&nbsp;{$lastpage}
{/if}
</p>
{/if}
{foreach from=$items item=entry}
<div class="CGBlogSummary">

{if $entry->postdate}
	<div class="CGBlogSummaryPostdate">
		{$entry->postdate|cms_date_format}
	</div>
{/if}

<div class="CGBlogSummaryLink">
<a href="{$entry->detail_url}" title="{$entry->title|escape:htmlall}">{$entry->title|escape}</a>
</div>

{if $entry->categories}
<div class="CGBlogSummaryCategory">
{strip}{$category_label}
 {foreach from=$entry->categories item='category'}
   {$category.name}&nbsp;
 {/foreach}
{/strip}
</div>
{/if}

{if $entry->author}
	<div class="CGBlogSummaryAuthor">
{gravatar width=80 height=80 email="$author_email"} {$author_label} {authorname username=$entry->author}
{getemail email=$entry->email}
	</div>
{/if}
 

{if $entry->summary}
	<div class="CGBlogSummarySummary">
		{eval var=$entry->summary}
	</div>

{else if $entry->content}

	<div class="CGBlogSummaryContent">
		{eval var=$entry->content}
	</div>
{/if}

{if isset($entry->extra)}
    <div class="CGBlogSummaryExtra">
        {eval var=$entry->extra}
	{* {cms_module module='Uploads' mode='simpleurl' upload_id=$entry->extravalue} *}
    </div>
{/if}
{if isset($entry->fields)}
  {foreach from=$entry->fields item='field'}
     <div class="CGBlogSummaryField">
        {if $field->type == 'file'}
          <img src="{$entry->file_location}/{$field->value}"/>
        {else}
          {$field->name}:&nbsp;{eval var=$field->value}
        {/if}
     </div>
  {/foreach}
{/if}

</div>
{/foreach}
<!-- End CGBlog Display Template -->
But I'm stilling getting "null". I'm learning a lot, but sure could use some guidance. I'm getting all the CGBlog summary template variables in here is the list of what I have thus far:

Code: Select all

app_name = CMS
cgsimple = Object
feu_smarty = Object
sitename = The X Agency
content_obj = Object
content_id = 64
page = x-blog
page_id = x-blog
page_name = x-blog
page_alias = x-blog
position = 5
friendly_position = 5
lang = en_US
encoding = utf-8
smarty = 
nls = Object
gcb_params = Array (1)
actionid = mb2673
actionparams = Array (2)
returnid = 64
actionmodule = CGBlog
menuparams = Array (4)
count = 4
nodelist = Array (4)
node = Object
mod = Object
CGBlog = Object
prevpage = <
firstpage = <<
nextpage = >
lastpage = >>
pagenumber = 1
pagecount = 1
oftext = of
pagetext = Page
itemcount = 1
items = Array (1)
category_label = Category:
author_label = Posted by:
statusopts = Array (2)
param_module = CGBlog
SCRIPT_NAME = /index.php

null -- (this is my UDT  result)
Thanks guys, I'm trying to get this down!

ER

Re: CGBlogs dynamic Gravatars

Posted: Sat Dec 01, 2012 1:53 pm
by manuel
Dear Erajis,

I don't have a lot of experience with this but I believe you have to update the UDT to work with the latest CMSMS.

Please try replacing

Code: Select all

global $gCms;
with

Code: Select all

$gCms = cmsms();

Code: Select all

$db =& $gCms->GetDb(); 
with

Code: Select all

$db = cmsms()->GetDb();
Greetings,
Manuel

Re: CGBlogs dynamic Gravatars

Posted: Sat Dec 01, 2012 3:07 pm
by Jo Morg
manuel wrote:Please try replacing
Code:
global $gCms;
with
Code:
$gCms = cmsms();


Code:
$db =& $gCms->GetDb();
with
Code:
$db = cmsms()->GetDb();
Once you have $gCms you can use $gCms->GetDb()
so this:

Code: Select all

$gCms = cmsms();
$db = $gCms->GetDb();
is also correct...


This is IIRC deprecated or even obsolete:

Code: Select all

$gCms->modules['FrontEndUsers']['object']
so if you need to get hold of FEU module you will need to use:

Code: Select all

$feu = cms_utils::get_module('FrontEndUsers');
But if $entry->email holds a valid email why on earth not use this:

Code: Select all

{gravatar width=80 height=80 email=$entry->email}