Wedge

Public area => The Pub => Plugins => Topic started by: txcas on January 28th, 2014, 03:15 AM

Title: Plugin request - Join date and location in posts
Post by: txcas on January 28th, 2014, 03:15 AM
This is a request from my users playing with Wedge.  I have the Join Date and Location in Posts mod installed on the SMF forum.
Title: Re: Plugin request - Join date and location in posts
Post by: Nao on January 28th, 2014, 10:11 AM
I think all of this is handled through custom fields in the Admin area. I'm not sure though, I haven't played with this in a long time.
Title: Re: Plugin request - Join date and location in posts
Post by: txcas on January 28th, 2014, 03:20 PM
You are right, I could disable the built-in location field in the profiles and add a new one that will show on posts.  The problem will be when migrating and existing site, that info will be lost if it was entered in the built-in location field.  I am not sure how to get the join date though, the SMF mod get is from the registration date.

         
Code: [Select]
if (!empty($modSettings['enable_join_date_post']) && (!$context['user']['is_guest']))
echo  '<li>', $txt['join_date'], ':  ', timeformat($message['member']['registered_timestamp'] ,'%b %Y'), '</li>';

if($context['user']['is_guest'] && !empty($modSettings['show_fields_to_guests']) && !empty($modSettings['enable_join_date_post']))
echo  '<li>', $txt['join_date'], ':  ', timeformat($message['member']['registered_timestamp'] ,'%b %Y'), '</li>';

//Show there location
if (!empty($modSettings['enable_member_location_post']) && !empty($message['member']['location']) && (!$context['user']['is_guest']))
echo '<li class="postcount">', $txt['location'], ': ', $message['member']['location'], '</li>';

if($context['user']['is_guest'] && !empty($modSettings['show_fields_to_guests']) && !empty($modSettings['enable_member_location_post']))
echo '<li class="postcount">', $txt['location'], ': ', $message['member']['location'], '</li>';

Title: Re: Plugin request - Join date and location in posts
Post by: Nao on January 28th, 2014, 04:51 PM
I'm a bit surprised; I *thought* that basic fields like Location were configurable. It turns out that you have to create a new field indeed, at which point you can determine if it should appear in posts or not.

I can probably write something that will let you choose any fields to show in the user box. Still, I'm not into that kind of stuff... I thought Pete wrote something for it. Maybe not.

It's not too hard to add Location to your user box, but unfortunately, Join Date isn't in $msg['member'] to begin with.

For Location, I would create a custom.xml file in /core/skins (and all of the skins I want to modify), with:

Code: [Select]
<?xml version="1.0"?>

<template name="template_msg_author_cf" where="before">
global $msg, $txt;

if (!$msg['member']['is_guest'] && !empty($msg['member']['location']))
echo '
<li class="location">', $txt['location'], ': ', $msg['member']['location'], '</li>';
</template>

This will add the Location field right before the custom fields list.
You can change the target template function, of course, and the location of your target function ('before', 'after', or 'override' if you want to completely remove the custom fields code.)

If you do things this way, you'll never have to worry about Wedge overwriting your changes when you update your files.
Well, as I said... Wedge templating is very powerful! :P
Title: Re: Plugin request - Join date and location in posts
Post by: Nao on January 28th, 2014, 04:59 PM
Just a like isn't gonna cut it... Make sure to keep me posted on this. :whistle:
More fields can be added this way, but if they're not in $msg['member'], you'll have to add them manually through some plugin or ask me to do it in the main codebase.
Title: Re: Plugin request - Join date and location in posts
Post by: txcas on January 28th, 2014, 05:09 PM
I just tested it and it worked like a charm for Location.  I need to learn more about templates in Wedge, but this is a good start.  I will try to make my own for join date or member since info.
Title: Re: Plugin request - Join date and location in posts
Post by: Nao on January 28th, 2014, 06:59 PM
Quote from txcas on January 28th, 2014, 05:09 PM
I just tested it and it worked like a charm for Location.
Great!
(Well, I wouldn't have posted the code if I hadn't already tested it on my local site, but at least you've proven that it's easy to do for anyone else, too!)
Quote from txcas on January 28th, 2014, 05:09 PM
I need to learn more about templates in Wedge, but this is a good start.  I will try to make my own for join date or member since info.
I haven't documented many things yet -- in fact, I've only documented whatever is in core/skins/Warm/skin.xml -- but the <template> keyword happens to be documented. I have yet to document instructions like <move>, <remove> and <rename>, though. Should also implement things like <add>, but I don't know if it's worth it...
Title: Re: Plugin request - Join date and location in posts
Post by: txcas on January 28th, 2014, 07:39 PM
Thanks for your help.  Do you have to add the registered_timestamp (join date or member since) to anything so it can be exposed like location?