HTML Logo by World Wide Web Consortium (www.w3.org). Click to learn more about our commitment to accessibility and standards.

Moving forward with Composr

ocPortal has been relaunched as Composr CMS, which is now in beta. ocPortal 9 will be superseded by Composr 10.

Head over to compo.sr for our new site, and to our migration roadmap. Existing ocPortal member accounts have been mirrored.


Custom Profile Fields question....

Login / Search

 [ Join | More ]
 Add topic 
Posted
Rating:
#91736 (In Topic #18434)
Avatar

Community saint

I started looking into these, and was glad to see there is an option by each one to show it in each post, which means less coding for me to figure out.  ;)

So I set some of them up as 'show in post' … made sure the data was filled out in the user profile.

None of it shows up.

Looked in OCF_TOPIC_POST.tpl, and in the block you would normally expect such a hook to be present in order to show them…  nothing.

Just curious if perhaps I missed something else, or if something is missing from OCF_TOPIC_POST.tpl

thanks.

Paul
Back to the top
 
Posted
Rating:
#91737
Avatar

Community saint

ah I see, it's for the popup box, not actually in the user info part of the post.

Paul
Back to the top
 
Posted
Rating:
#91738
Avatar

There's a Tempcode symbol to pull in CPFs if required.


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#91739
Avatar

Community saint

Chris, a possible 'bug' :

Of note, in off_topicview.php you will find:

Code (php)

// Any custom fields to show?
$post['custom_fields']=ocf_get_all_custom_fields_match_member($_postdetails['p_poster'],((get_member()!=$_postdetails['p_poster']) && (!has_specific_permission(get_member(),'view_any_profile_field')))?1:NULL,((get_member()==$_postdetails['p_poster']) && (!has_specific_permission(get_member(),'view_any_profile_field')))?1:NULL,NULL,NULL,NULL,NULL,NULL,0,true);

According to ocf_get_all_custom_fields_match_member, the 'true' at the end is for 'show_on_join_form', meaning the only fields it will bring back and show are those that also have set 'show_on_join_form'… which doesn't make sense…  the important one in all of this is 'public_view' set to true and 'show_in_posts' set to true.  

I came to realize this as I had two fields and only one was showing up…   So I changed that line to this:

Code (php)

          $post['custom_fields']=ocf_get_all_custom_fields_match_member($_postdetails['p_poster'],1,NULL,NULL,NULL,NULL,1,NULL,0,NULL);

Works like a charm now, brings back all fields that are both publicly viewable AND set to show in posts.



Last edit: by Arbo

Paul
Back to the top
 
Posted
Item has a rating of 5 (Liked by Jean)  
Rating:
#91740
Avatar

Community saint

For those that want such fields displayed on the screen, not just in a popup:

In topicview, find the comment below, replace that  section of code with this:

Code (php)


                                // Poster details
                                if (!$is_spacer_post)
                                {
                                    $popup_fields=new ocp_tempcode();
                                        $show_cpf=new ocp_tempcode();
                                       
                        foreach ($_postdetails['custom_fields'] as $name=>$value)
                        {
                              if ((!is_null($value['RENDERED'])) && ($value['RENDERED']!==''))
                                //echo "N[".$name."]V[".$value['RENDERED']."]<br />";
                                    $show_cpf->attach(do_template('OCF_MEMBER_BOX_CUSTOM_FIELD2',array('_GUID'=>'10b72cd1ec240c315e56bc8a0f3a92a1','NAME'=>$name,'VALUE'=>$value['RENDERED'])));
                        }

                                        if (!is_guest($_postdetails['poster']))
                                        {
                                                require_code('ocf_members2');
                                                $poster_details=render_member_box($_postdetails,false,$hooks,$hook_objects,false);
                                        } else
                                        {
                                                if (array_key_exists('ip_address',$_postdetails))
                                                {
                                                        $popup_fields->attach(do_template('OCF_MEMBER_BOX_CUSTOM_FIELD',array('_GUID'=>'d85be094dff0d039a64120d6f8f381bb','NAME'=>do_lang_tempcode('IP_ADDRESS'),'VALUE'=>($_postdetails['ip_address']))));
                                                        $poster_details=do_template('OCF_GUEST_DETAILS',array('_GUID'=>'e43534acaf598008602e8da8f9725f38','CUSTOM_FIELDS'=>$popup_fields));
                                                } else
                                                {
                                                        $poster_details=new ocp_tempcode();
                                                }
                                        }
                                } else
                                {
                                    $show_cpf=new ocp_tempcode();
                                        $poster_details=new ocp_tempcode();
                                }
 

Further down at the $rendered_post=do_template …  at the bottom of the list of all the var's it sends to the template, add:

Code (php)

 'SHOW_CPF'=>$show_cpf,
 

You need to make OCF_MEMBER_BOX_CUSTOM_FIELD2.tpl :

Code

 <div>{NAME*}: {VALUE*}</div>

and in OCF_TOPIC_POST.tpl add the show_cpf line as seen here:

Code

<div class="ocf_topic_poster_more">
             {+START,IF_NON_EMPTY,{POSTER_TITLE}}<div class="ocf_topic_poster_title">{POSTER_TITLE*}</div>{+END}
            {POST_AVATAR}
            {+START,IF_NON_EMPTY,{RANK_IMAGES}}<div class="ocf_topic_poster_rank_images">{RANK_IMAGES}</div>{+END}
            {+START,IF_NON_EMPTY,{SHOW_CPF}}<div class="ocf_topic_poster_title">{SHOW_CPF}</div>{+END}
         </div>

I just wanted a few of those fields to show down there… I don't like the whole popup thing, and plan to get rid of it…       


Last edit: by Arbo

Paul
Back to the top
 
Posted
Rating:
#91741
Avatar

Community saint

Ah, this one got me too… you also need, in  sources_custom/ocf_posts2.php

at the bottom of the list of variables passed in do_template, you need to add

Code

 'SHOW_CPF'=>'';

Or you'll get a warning about it being referenced but not passed when you reply to a message.

Paul
Back to the top
 
Posted
Rating:
#91751
Avatar

Community saint

Forgot to put up an image of what this looks like…   in my case, I have selected 'location' as one to show in posts, as well as another I made called 'lean' …




(I did some other CSS changes in there as well)

Paul
Back to the top
 
Posted
Rating:
#91752
Avatar

Arbo said

Chris, a possible 'bug' :

Of note, in off_topicview.php you will find:

Code (php)

// Any custom fields to show?
$post['custom_fields']=ocf_get_all_custom_fields_match_member($_postdetails['p_poster'],((get_member()!=$_postdetails['p_poster']) && (!has_specific_permission(get_member(),'view_any_profile_field')))?1:NULL,((get_member()==$_postdetails['p_poster']) && (!has_specific_permission(get_member(),'view_any_profile_field')))?1:NULL,NULL,NULL,NULL,NULL,NULL,0,true);

According to ocf_get_all_custom_fields_match_member, the 'true' at the end is for 'show_on_join_form', meaning the only fields it will bring back and show are those that also have set 'show_on_join_form'… which doesn't make sense…  the important one in all of this is 'public_view' set to true and 'show_in_posts' set to true.  

I came to realize this as I had two fields and only one was showing up…   So I changed that line to this:

Code (php)

          $post['custom_fields']=ocf_get_all_custom_fields_match_member($_postdetails['p_poster'],1,NULL,NULL,NULL,NULL,1,NULL,0,NULL);

Works like a charm now, brings back all fields that are both publicly viewable AND set to show in posts.



Thanks, it should actually be:

Code


      $post['custom_fields']=ocf_get_all_custom_fields_match_member($_postdetails['p_poster'],((get_member()!=$_postdetails['p_poster']) && (!has_specific_permission(get_member(),'view_any_profile_field')))?1:NULL,((get_member()==$_postdetails['p_poster']) && (!has_specific_permission(get_member(),'view_any_profile_field')))?1:NULL,NULL,NULL,NULL,1);

As $show_in_posts was meant to be 1 rather than $show_on_join_form being true.


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#91754
Avatar

Community saint

Doesn't

Code

(get_member()!=$_postdetails['p_poster']) && (!has_specific_permission(get_member(),'view_any_profile_field')))?1

(if member viewing is not equal to person that posted this message)   &&  ( member viewing can view any profile field) ?

I took view any profile field as the privilege meaning you can view even non public fields.  And I figured it should show them even if the member viewing is the member that made the post.  The popup worked the same way, you could view your own info.

Thus I just put a '1' in there.   For if the field is both 'show_in_posts' AND publicly viewable, it should show up.   Though I couldn't think why someone would put a field as show_in_posts AND not publicly viewable…

Paul
Back to the top
 
Posted
Rating:
#91756
Avatar

Nope:
  1. Putting a '1' in there is more restrictive, not less restrictive. It is saying returned fields have to match that.
  2. You said "member viewing can view any profile field", but it's "member viewing can't view any profile field", due to the "!".


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#91757
Avatar

Community saint

Chris Graham said

Nope:
  1. Putting a '1' in there is more restrictive, not less restrictive. It is saying returned fields have to match that.
  2. You said "member viewing can view any profile field", but it's "member viewing can't view any profile field", due to the "!".

1.  I think I see what you are saying, if you send just a '1' to 'show_in_posts', you get every one back that has that set, it doesn't matter if 'public_view' is 0 or 1 …    so with the code you have for the second field if a user is viewing a post from another user and the viewing user doesn't have permission to view all fields no matter what, then it returns only publicly available fields.   If they are not viewing their own post && they have permission to view all fields it sends a NULL, in which case the function can send back non-publicly viewable stuff that is 'show_in_post'.

Ok, I modified a field no 'publicly viewable' as no.. but show in post as yes.

An admin can see that field.   And the user can see it on their own posts.  Or if view any member profile fields privilege is set to yes for whatever usergroup they belong to they can see that field.

Got it.

2. yeah, my misreading.  




Paul
Back to the top
 
Posted
Rating:
#91759
Avatar

Community saint

an update, that OCF_MEMBER_BOX_CUSTOM_FIELD2.tpl should be

Code

<div>{NAME*}: {VALUE}</div>

removed the * after value, because in one of my fields that passes an image, the * passes the text unparsed, so you get all the img tags and such…

Paul
Back to the top
 
Posted
Rating:
#91825
Avatar

Community saint

A fix for this, it seems it causes issues when you get a PT notification from the system, as at that point there are no 'custom_fields' in the postdetails array…  

So from the modified code above in topicview.php
you'll need to add a check to see if 'custom_view' exists or not..  code should look like this

Code

    if ((!$is_spacer_post) && (array_key_exists('custom_fields',$_postdetails)))
            {
                  $show_cpf=new ocp_tempcode();
                  
                  
                     foreach ($_postdetails['custom_fields'] as $name=>$value)
                     {
                      if ((!is_null($value['RENDERED'])) && ($value['RENDERED']!==''))
                        //echo "N[".$name."]V[".$value['RENDERED']."]<br />";
                       $show_cpf->attach(do_template('OCF_MEMBER_BOX_CUSTOM_FIELD2',array('_GUID'=>'10b72cd1ec240c315e56bc8a0f3a92a3','NAME'=>$name,'VALUE'=>$value['RENDERED'])));
                     }
               
            } else
            {
                $show_cpf=new ocp_tempcode();
            }

if array_key_exists is the added logic loop needed.

edit: changed the layout a bit…


Last edit: by Arbo

Paul
Back to the top
 
Posted
Rating:
#91865
Avatar

Community saint

Added this to the wiki thing…

Adding CPF's (and other data) below users avatar in posts - ocPortal.com

Also:

– note.  I plan to follow this up with adding in a joined data (shorted to month and year), # of posts, and possibly a few other items.  I will probably make the visibility of those items configuration options.

Paul
Back to the top
 
1 guests and 0 members have just viewed this: None
Control functions:

Quick reply   Contract

Your name:
Your message: