Support Forum

Advanced Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
coding-topic
How to filter Forum Display Name?
Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
May 17, 2012 - 4:51 pm

Whoops. Sorry - I left out a line of code..

Should be:

add_filter('sph_user_class_meta', 'sph_addMetatoObj');
function sph_addMetatoObj($objList) {
    $objList['cortesia'] = 'title';
    return $objList;
}

Needs that return statement.

andy-signature.png
YELLOW
SWORDFISH
Avatar
bluantinoo
ITA
Member
Free Members
sp_UserOfflineSmall Offline
May 17, 2012 - 5:35 pm

Yep it's working!

it's missing just on "first post from" and "last post from" labels on forum lists

thank you very much! 🙂

just one little more question, as I do not fully understand you code...
in this line: $objList['cortesia'] = 'title';

if "cortesia" stands for the name of my usermeta, what "title" stands for?

Avatar
Mr Papa
Simi Valley, CA
SP Master
Free Members
sp_UserOfflineSmall Offline
May 17, 2012 - 10:46 pm

title is simple a flag or switch for us... it tells us how to filter the object for display...

Avatar
bluantinoo
ITA
Member
Free Members
sp_UserOfflineSmall Offline
May 18, 2012 - 4:18 am

but it could be whatever string, right? I've tried with other than "title" and it works as well

Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
May 18, 2012 - 4:47 am

All data that is user entered needs to be filtered and sanitised to ensure there is nothing malicious in it - like an attempt to run SQL or javascript. SP has a series of display filters that does just this and ALL data is passed through the filters before being displayed or used. The reference to 'title' tells the system what filter to run that data item through and is probably the best one for your needs. It does not - for example - allow HTML tags within the data.

if you go the forum admin > toolbox > data inspector and turn on the option to display spThisUser when you run, say, the front page of the forum, it will display all of the data that is a part of our user object and you will see how the filters we changed yesterday have become a part of that object.

andy-signature.png
YELLOW
SWORDFISH
Avatar
bluantinoo
ITA
Member
Free Members
sp_UserOfflineSmall Offline
May 18, 2012 - 5:14 am

Ok,

I've looked forward for trying to add that usermeta in places where it is not shown with that awesome filter.

I mean in places like "last post" "topic started"

I see that datas are shown by functions like

sp_TopicIndexFirstPost

sp_TopicIndexLastPost

is there a way to filter theese as well?

Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
May 18, 2012 - 2:19 pm

This is where it gets a bit moire tricky.
You would need to use the filter on the code that builds the data object. This would give you an array of topic data along with the posts data which would include the user ID and the display name.
Your code would then need to traverse the array and change all the instances of display_name. You would need to lookup the data you want to prepend for each user as you work through the data array.
No so easy

andy-signature.png
YELLOW
SWORDFISH
Avatar
bluantinoo
ITA
Member
Free Members
sp_UserOfflineSmall Offline
May 22, 2012 - 12:29 pm

Hi Sword,

sorry to persist bothering you with this issue, but I need some more help to achieve this.

Let's start with the "group view" screen (that I think is the forum home, right?).

Using the wonderful Data Inspector I can see that there are 3 objects in Group View Data that contain the user display name.

1) spThisForum

2) spThisGroup

3) spGroupView

Wich one would be better try to manipulate to filter display name of "last message from" in Group View?

Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
May 22, 2012 - 2:31 pm

Well it's $spThisForum at that point and the last post column has a filter defined of 'sph_ForumIndexLastPost' but that is going to contain all of the text for that display element - not just the display name.

However the 'sph_groupview_stats_records' filter will pass an array of all the data for the page (the stats data that is) which would be better. You could then loop through the array changing each instance of display_name to what you need. This filter passes two parameters - the data object we are going to use for the final display and a second parameter containing the raw data as retrieved from the database. You would want to operate ion the first of course.

andy-signature.png
YELLOW
SWORDFISH
Avatar
bluantinoo
ITA
Member
Free Members
sp_UserOfflineSmall Offline
May 23, 2012 - 11:44 am

Hi Swordfish,

I'm sorry but I really don't understand how to start 🙁

Could you please show me some example code?

Forum Timezone: Europe/Stockholm
Most Users Ever Online: 1170
Currently Online:
Guest(s) 1
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Mr Papa: 19448
Ike: 2086
Brandon: 864
kvr28: 804
jim: 650
FidoSysop: 577
Conrad_Farlow: 531
fiddlerman: 358
Stefano Prete: 325
Member Stats:
Guest Posters: 617
Members: 17359
Moderators: 0
Admins: 4
Forum Stats:
Groups: 7
Forums: 17
Topics: 10125
Posts: 79620