Hi,

Can I asked how is facebook style status integrated with advanced forum? I can see it with the activity module though...

CommentFileSizeAuthor
#44 facebook_status.author-pane.inc_.txt415 bytesmichelle

Comments

michelle’s picture

Status: Active » Fixed

The $facebook_status variable is available in advf-author-pane.tpl.php

Michelle

dropchew’s picture

Thanks! I just found out from the thread here http://drupal.org/node/302125

Flying Drupalist’s picture

Does this only work with adv forum?

Can I:

print facebook_status_advf($account);

Anywhere else?

icecreamyou’s picture

If $account is a complete user object, then yes, you can. It will print the user's (abbreviated) status surrounded by <span class="submitted"></span>.

However, if you want to display a user's status somewhere, I suggest you use the function facebook_status_get_status($uid). It returns an array of arrays, so you could do this:

global $user;
$status = facebook_status_get_status($user->uid);
echo theme_username($user) .' '. check_plain($status[0]['status_fb']) .' <span class="submitted">'. format_interval(time() - $status[0]['status_time']) .' ago</span>';

...and it would print something like:

IceCreamYou is happy a moment ago.

michelle’s picture

Oh, that's a nicer function. I just used the one you told me and didn't look closer since I'm not actually using the module myself right now. Is there any reason I can't just use that one?

Michelle

icecreamyou’s picture

The text facebook_status_advf() returns is formatted differently: it's smaller (on most themes) and doesn't include the posted-date. Plus it requires using a lot less code in advanced_forum to implement it, which also makes it easier for me to change things if I need to. And facebook_status_advf() automatically truncates the status (and in the next -dev release, will include a tooltip with the full status).

Further, facebook_status_advf() checks for user_relationships (and, in the next -dev, friendlist relationships) and restricts viewing the status to users with a relationship to the owner of the node/comment.

So basically, no, you shouldn't.

michelle’s picture

Ah, I see, that makes sense. Though if you want it easier for you to change it, why not just put it into facebook_status? Then you have total control. Just tell me if you change the variable name(s). :)

Michelle

icecreamyou’s picture

Though if you want it easier for you to change it, why not just put it into facebook_status? Then you have total control. Just tell me if you change the variable name(s). :)

What do you mean? Is there a way for me to add something to the advf interface directly from facebook_status.module? Otherwise, it's already as simple as it can get, and unless I want a new parameter passed to facebook_status_advf(), I do have total control. ;)

michelle’s picture

"Is there a way for me to add something to the advf interface directly from facebook_status.module?"

Yes. I mentioned that in http://drupal.org/node/302125#comment-990386 but then you provided the function and I figured it was easy enough for me to just add it in.

Odd... I could have sworn I documented this but I don't see it now... Will have to add that. Anyway, if you look at the integration code you can see that all I did was add a function to your module and put it in my module's directory. So just take it and put it in your own module. (And let me know so I can take it out of mine). If you don't want it in the .module file itself, just copy the whole facebook_status.forum.inc file to your project and AF will find it and include it automatically.

The important line is $variables['facebook_status']. That will make a variable in the template file named $facebook_status. If you want to provide more variables, that's fine. Just let me know so I can document them in the template file header.

At the moment, the variable is just provided to the template; it's not printed by default. The sentence is long and looked a little funny so I figured I'd leave it up to the admin if they wanted to add it. I'm rethinking that, though, and I guess it makes more sense just to let them take it out if they don't want it. No reason f_s should be any different than any of the other ones. I'll make that change before the next alpha so let me know if you want to change the variable name. :)

Michelle

icecreamyou’s picture

Well--if you want people to just be able to delete it, maybe it's better if it stays with the other related files. Otherwise I'm happy to include it with facebook_status. I assume it works with both 5.x and 6.x?

If you do end up not printing it by default, let me know so I can provide instructions on how to get it working.

michelle’s picture

I think you're misunderstanding. I'm not expecting people to delete the integration code as that would require hacking the module. What I'm saying is right now I don't have print $facebook_status in the .tpl files that ship with the module but the variable is there if people want to add it. I decided to do the reverse and put it in by default and people can delete that line if they don't want it.

Either way, you can put the facebook_status_preprocess_author_pane function right in your module if you like and I'll just remove it from mine. Just need to make sure it's not in both places or we'll get naming conflicts.

Michelle

icecreamyou’s picture

Ah.

Well then, I'll just go ahead and put this in with the next -dev release, assuming it works with both 5.x and 6.x. I can post here to let you know when the next -dev is released if you'd like (probably before this Sunday) or we can do something else if you have a better idea for coordinating the switch.

michelle’s picture

Status: Fixed » Active

Sorry, forgot to answer your question. Yes, the hook is the same in both 5.x and 6.x and will be in 7.x unless something unexpected makes me change it. So the only thing you need to worry about your end, once we get the function switched over, is to let me know if you ever decide to change the variable or add more variables.

I'm going to be doing a bug fix release probably early next week. It would probably better to wait until then. I think it's better to have a short period where the function is taken out of AF and waiting on you to add it to FS than to have a period where it's added to FS and not taken out of AF and people are getting errors.

Sorry for the confusion. I should have made it clearer from the start that you could add it to FS. I mentioned it briefly but never followed up when you provided the function and just assumed you didn't want to rather than realizing you didn't catch that you could.

Setting this back to active for the moment until it's all resolved.

Michelle

icecreamyou’s picture

Will wait to include it then. Thanks.

Flying Drupalist’s picture

So what should I do in the meantime? Use for now:

global $user;
$status = facebook_status_get_status($user->uid);
echo theme_username($user) .' '. check_plain($status[0]['status_fb']) .' <span class="submitted">'. format_interval(time() - $status[0]['status_time']) .' ago</span>';

Later:

print $facebook_status 

?

Do you have any idea when $facebook_status will be working? Thanks.

icecreamyou’s picture

What do you want to do? Where do you want this to show up?

If you want integration with Advanced Forum, you can do print $facebook_status; or print facebook_status_advf($account); right now; both work. If you want to print the status somewhere else, use the code I gave for facebook_status_get_status().

Flying Drupalist’s picture

Will

print $facebook_status; 

ever work with non-advanced forum, or is that an advanced forum only feature?

I'm going to use facebook_status_get_status(). but I much prefer only 1 line. Not that it makes that big of a difference. xD

michelle’s picture

That variable is specific to the advf-author-pane.tpl.php file. Otherwise you need to use a function call.

Michelle

icecreamyou’s picture

$facebook_status only works with advanced_forum because advanced_forum stores the result of facebook_status_advf($account) in that variable for theming purposes.

If you want an abbreviated status, do this (change '25' to whatever number you need):

global $user;
$status = facebook_status_get_status($user->uid);
$status_orig = check_plain($user->name .' '. $status[0]['status_fb']);
if (drupal_strlen($status[0]['status_fb']) > 25) {
  $status[0]['status_fb'] = drupal_substr($status[0]['status_fb'], 0, 25) .'...';
}
echo '<span title="'. $status_orig .'">'. theme_username($user) .' '. check_plain($status[0]['status_fb']) .'</span> <span class="submitted">'. format_interval(time() - $status[0]['status_time'], 1) .' ago</span>';
Flying Drupalist’s picture

Thank you both, thanks a lot :).

Flying Drupalist’s picture

Hi, I have decided to use this:

global $user;
$status = facebook_status_get_status($user->uid);
echo theme_username($user) .' '. check_plain($status[0]['status_fb']) .' <span class="submitted">'. format_interval(time() - $status[0]['status_time']) .' ago</span>';

It doesn't work if the user has no status set. It wouuld be nice if it becomes the update form to that user and is empty to other users in that case.

Thanks.

michelle’s picture

That's going to show the status of the logged in user, not the forum post author.

Michelle

Flying Drupalist’s picture

Thanks you're right Michelle. I tried the other code and it was the same thing. How do I get it to display the status of poster? Thanks.

michelle’s picture

Use the $account variable.

Michelle

Flying Drupalist’s picture

Sorry, I have no idea how to do that. :) Please help if you have the time.

Thanks.

icecreamyou’s picture

Can you please explain exactly what it is you're trying to do and where you're trying to do it? Otherwise I can't help you at all.

Flying Drupalist’s picture

I apologize for the confusing question.

I'm trying to output the poster's status under their picture on nodes and comments. It would ideally display something like : IceCreamYou is happy a moment ago. if status is set. Nothing is status is not set. And appearing to the poster him/herself is the clickable status, which displays the status form onclick regardless if status is set or not set.

Thanks.

icecreamyou’s picture

That is quite a bit more complex than what I was expecting, and also takes up quite a bit more room than you probably have. I recommend keeping the status form in a separate block and simply using print $facebook_status; in your advf-forum-user.tpl.php.

Flying Drupalist’s picture

I'm not using adv forum.

I'm wondering how you would display something equivalent for someone who's not using adv forum, disregarding this part:"
And appearing to the poster him/herself is the clickable status, which displays the status form onclick regardless if status is set or not set."

icecreamyou’s picture

Hmm.

I'd do something like this then:

$uid = db_result(db_query("SELECT uid FROM {comments} WHERE cid = %d", $cid));
$account = user_load(array('uid' => $uid));
$status = facebook_status_get_status($account->uid);
echo theme_username($account) .' '. check_plain($status[0]['status_fb']) .' <span class="submitted">'. format_interval(time() - $status[0]['status_time']) .' ago</span>';

But you'll need to figure out how to get the $cid yourself.

And also - your question is unrelated to this issue. Please open another issue next time.

Flying Drupalist’s picture

Hi IceCreamYou, thank you for your help. But I have no idea how to get $cid.

Originally I was just asking if the code for advance forum could be used elsewhere because I thought you wrote a generic theme output, I didn't realize it was tailored specifically for advanced forum. I apologize for that.

icecreamyou’s picture

Well, the function works anywhere, you just have to pass a user object to it. It's just that it's themed in such a way that it's most appropriate for use with Advanced Forum.

For $cid it might change depending on your theme and what files you're trying to do this in. I believe that if you have a comment.tpl.php it gets passed the $comment object so $cid = $comment->cid (although I'm not sure). If you want this on nodes too, just use db_query("SELECT uid FROM {node} WHERE nid = %d", arg(1)); instead.

Flying Drupalist’s picture

Hi, thanks for your help.

Do you mean something like this for comments?

$uid = db_result(db_query("SELECT uid FROM {comments} WHERE cid = %d", $comment->cid));
$account = user_load(array('uid' => $uid));
$status = facebook_status_get_status($account->uid);
echo theme_username($account) .' '. check_plain($status[0]['status_fb']) .' <span class="submitted">'. format_interval(time() - $status[0]['status_time']) .' ago</span>';

I have no idea where to put the database query.

icecreamyou’s picture

Yes, that's what I mean.

For nodes, do the same, but replace the $uid query appropriately. And contrary to what I said earlier, use $node->nid if it works instead of arg(1) so that you don't get unwanted results if you display nodes on pages other than the node page itself (like in Views).

Flying Drupalist’s picture

Thanks a lot. How would I not display anything if the user does not have a status set?

icecreamyou’s picture

Wrap the echo in if ($status[0]['status_fb']) {}.

Note that this will cause the status to not show up if the status is (A) not set, (B) '0' (zero), or (C) blank/cleared. If you want (B) and (C) to show up, use if ($status[0]['status_time']) {} instead. (Technically, (C) is not supposed to validate, but validation isn't working right now I think. It's on my list of things to fix.)

Flying Drupalist’s picture

Thank you very much. Works as I like. I don't really understand the differences between A/B/C, but I think leaving it on if ($status[0]['status_fb']) {} will be OK for me. Thank you very much.

Flying Drupalist’s picture

Oh hey by the way, if anon users post that gives an error. Can you edit the snippet a little so that it also displays nothing for anon?

icecreamyou’s picture

After you find the $uid, wrap the rest in if ($uid) {}

michelle’s picture

Sorry, IceCreamYou, I totally spaced on taking this out of AF before the release. The current dev is in feature adding mode and I advise people not to use it so I guess it wouldn't hurt to take it out now. When are you planning a release? It will probably be a few weeks until my next release so I can do it when its convenient for you.

Michelle

icecreamyou’s picture

facebook_status is technically in -dev so it's not a problem to release an update just to add in the necessary file. That means I can do it whenever you tell me I can.

In terms of development, I'll probably be ready for an update this weekend.

michelle’s picture

Actually, shoot... I was thinking of this backwards. I was thinking it's no big deal if I take it out because people shouldn't be using my dev right now anyway. But if you put it in, it's going to have a name collision on anyone using alpha 13. :( Dang, I should have started a policy of having the integration in the helper modules to begin with. This is messy. I guess it's going to have to wait until I release alpha 14, after all.

Sorry,

Michelle

icecreamyou’s picture

No big deal, just let me know when I should add the file.

michelle’s picture

StatusFileSize
new415 bytes

Ok, I've started the switch over to get all the contrib code out of AF because I'm rewriting APK to use the same code so need it to be in the contrib modules themselves. It's just going to be messy for a while until the dust settles. Go ahead and add the file / function whenever you're ready. I've also documented it here: Adding variables to the author pane

Thanks,

Michelle

icecreamyou’s picture

Status: Active » Fixed

Will do, soon...

I've been really busy lately and also working on some changes to the 6.x branch, so this will go into 5.x probably today but I have no idea when I'll next have a 6.x release.

Anyway, thanks for the heads-up. Marking as fixed even though this isn't actually in CVS yet because I already have it in my local dev folders so it will definitely be in the next release.

michelle’s picture

Ok, sounds good. I've got issues on the 7 other contrib modules that I was including in AF. It's going to be a bumpy road but hopefully will all be sorted by the time I do a 1.0 of AF. *crosses fingers*

Michelle

icecreamyou’s picture

No beta/RC first? :O ;)

Committed to 5.x. I think. I messed up the first time and added an older, differently named version, but it *should* be removed...

icecreamyou’s picture

Committed to 6.x also after I remembered that I don't work directly out of the CVS directory so there won't be any changes there. :-P

...hopefully.

michelle’s picture

Yes, I'll be doing betas and RCs. See http://drupal.org/node/326461

Thanks for taking care of this. One I can check off my list. 6 to go :)

Michelle

icecreamyou’s picture

Version: 5.x-1.x-dev » 6.x-1.x-dev
Component: User interface » Miscellaneous
Status: Fixed » Closed (fixed)

Sweet.