EDIT: If someone think this is not possible, please post then i need to rethink my blog quick.
Hello.
I’m making an traditional blog.
For "showing blog posts" im using Ditto.
For "login" im using WebLoginPE, where the option to upload a user photo exsist within the user profile page.
For "posting on my blog" im using NewsPublisher.
Now, is it possible to output a persons user photo somewhere in my ditto "&tpl", so that the person blogging has his user photo displayed next to his post.
Thanks
I was just working on a similar thing, try this and see if it works for you:
Create a new snippet with the code below, name it Author_photo.
Call the snippet in your ditto template where you want the image to appear according to the example in the top of the snippet code.
<?php
/* Author_photo
Ditto blog template:
[!Author_photo? &authid=`[+createdby+]`!]
Jot Comment template:
[!Author_photo? &authid=`[+comment.createdby+]`!]
*/
// set this to the path of a default avatar image in case the user does not have a profile pic
$defaultavatar ='<img src="assets/images/avatars/defaultuser.gif" alt="Anonymous user" border="0" />';
$output ='';
$tbl = $modx->dbConfig['table_prefix'];
$authorID = isset($authid) ? $authid : $modx->documentObject['createdby'];
$addutype ='';
if($authorID !='' && $authorID < 0){
$addutype ='web_';
}
// anonymous comments are given 0 creator id apparently
if($authorID == 0){
$output .=$defaultavatar;
}else{
if($authorID != ''){
$authorID = str_replace('-','', $authorID);
$sql = "SELECT fullname,photo
FROM ".$tbl.$addutype."user_attributes
WHERE internalKey='".$authorID."'";
$rs = $this->dbQuery($sql);
$limit = $this->recordCount($rs);
if($limit > 0 && $limit < 2) {
$user = $this->fetchRow($rs);
if($user['photo'] != ''){
$modx->setPlaceholder('author_photo', '<a href="#"><img src="'.$user['photo'].'" alt="'.$user['fullname'].'" border="0" /></a>'); // [+author_photo+]
}else{
$modx->setPlaceholder('author_photo', '<a href="#">'.$defaultavatar.'</a>');
}
$output .='[+author_photo+]';
}
}else{
$output .=$defaultavatar;
}
}
return $output;
?>
Hope this helps
Hey breezer, what a great snippet!!
I got it to display the default user image, but not recognize the user photo.
Also, only thing i changed in your snippet was the url to my default image:
assets/snippets/webloginpe/userimages/default_user.jpg
I don’t use webloginpe, so I’m not sure how it stores (path wise) the user images. It’s probably a path issue as this just grabs whatever is stored in the database in the user properties.
It’s strange because i see no problem in why it shouldn’t work with webLoginPE, that said im not genius php programmer nor db expert.
I found the table user_attributes in my db, and under photo my images are displayed like this:
assets/snippets/webloginpe/userimages/jonas.png
I think I see the issue, I had tested it on the blog page summary and with jot comments (pics show in both for me ok), if you are using it on a blog page that is the single blog entry, try these two things:
1. Try calling the snippet without an authid variable and it should default to the document creator.
[!Author_photo!]
2. If this is on a summary page, add this to your page ditto snippet call: &hiddenfields=`createdby` (try it with/without the authid=``)
Hello can you please re link your snippet zip it’s off line thx