[DEV] jQ User Map api3

Mod Support

Moderators: BNa, Sekuro, 4seven

Re: [DEV] jQ User Map api3

Postby javiexin » 10 Jul 2012, 10:22

Sorry to jump in, but I would STRONGLY recommend AGAINST the use of profile field NAMES as conditionals. PF Names are language-dependant, and therefore, if you plan to use your board with more than one language, this use would immediately create issues. And besides, PF Names might be changed, and that should not break any code.

Instead, you should use profile field IDENTIFIERS, which are language-independent, cannot be changed, and therefore are safe to use in conditionals.

To use this, you just would need to "assign_var" the result of the call to $cp->generate_profile_fields_template('show'... (look in memberlist.php for an example of how this is done), and then you would have available multiple template variables:
Code: Select all
'PROFILE_XXXX_NAME' -> This is the language dependent name of the profile field
'PROFILE_XXXX_EXPLAIN' -> This is the language dependent explantation of what this profile field represents
'PROFILE_XXXX_TYPE' -> The type of the variable, as defined when the CPF was created
'PROFILE_XXXX_VALUE' -> The value of the profile field
'S_PROFILE_XXXX' -> switch to be used in conditionalswill be true if the user has this profile field defined

In all these cases the XXXX is the fully upper-case profile field IDENTIFIER, that is language independent.

In your example above, you could use in the template things like <!-- IF S_PROFILE_DRIVES -->{PROFILE_DRIVES_VALUE}<!-- ENDIF--> assuming that 'drives" is the identifier of a certain CPF (note this is the IDENTIFIER, not the name, that might be 'Drives' in English, or 'Conduce' in Spanish... sorry no German :()

While I agree with 4_seven that producing the full HTML in PHP might be easier, in certain cases you will be much better off having the flexibility to use the CPFs individually, and offloading the full HTML structure to your Template file (where it actually belongs...). That way, you will also ease the work of style authors, that want individual CONTENT variables, and not markup ones, as this will limit their freedom to create new styles.

Hope this helps. Please, don't take this as contentious, but just as a generic comments on the use of CPFs... Regards,
-javiexin
javiexin

Tiptop

Tiptop
 
Posts: 8
Joined: 26 Jun 2012, 12:56
 
Resolution: 1600x898


Re: [DEV] jQ User Map api3

Postby 4seven » 10 Jul 2012, 15:53

This was build from the scratch. An Addition v.0.0.2 was planned before this Addition v.0.0.1 comes out and is in progress yet. The issues you told me was very well known by me before ;) Through my 3 CPF Mods now, i have enough knowledge in this stuff. I just want to have a base version for the OP, later we see more.
Current Mods | Mod Base | php(BB) programming | No help via PM
User avatar
4seven

Tiptop

Tiptop
 
Posts: 318
Joined: 20 Jun 2012, 16:55
 
Resolution: 1920x1080


Re: [DEV] jQ User Map api3

Postby volksdevil » 10 Jul 2012, 15:54

EDIT: Ahhh, 4seven already knew/replied just before me. 8-)

javiexin wrote:In your example above, you could use in the template things like <!-- IF S_PROFILE_DRIVES -->{PROFILE_DRIVES_VALUE}<!-- ENDIF-->
-javiexin


javiexin, that sounds perfect! as that's what tends to happen when showing cpf's elsewhere such as memberlist/viewing profiles etc.

Now I'll be honest, I'm clueless as far as php, all I know is that 4sevens idea's and codes are superb! and I'm sure he will be the type of guy to appreciate any input to make his mods even better than they already are (Superb!)

I appreciate the time you both put in from what I've seen, so forgive me for asking...which files do I edit, and exactly where do I put what? :oops: If they could be edited for me, or explain what to do it would be greatly appreciated.

I'm at work at the moment but I'll pop the files up here.

user_map.php
Code: Select all
// Load custom profile fields / Addition
            $cp_row    = $cp->generate_profile_fields_template('show', false, $profile_fields_cache[$row['user_id']]);
            $full_prof = '';
            for ($i = 0, $end = sizeof(@$cp_row['blockrow']); $i < $end; ++$i){
            if (
                ($cp_row['blockrow'][$i]["PROFILE_FIELD_NAME"] == 'Real name')
            ||  ($cp_row['blockrow'][$i]["PROFILE_FIELD_NAME"] == 'Gender')
            ||  ($cp_row['blockrow'][$i]["PROFILE_FIELD_NAME"] == 'Driving')
            ||  ($cp_row['blockrow'][$i]["PROFILE_FIELD_NAME"] == 'Location')
            ||  ($cp_row['blockrow'][$i]["PROFILE_FIELD_NAME"] == 'Can help with')

            ){
            $full_prof   .= '<strong>' . $cp_row['blockrow'][$i]["PROFILE_FIELD_NAME"] . ':</strong> ' . $cp_row['blockrow'][$i]["PROFILE_FIELD_VALUE"] . '<br /><br />';}}
            // Load custom profile fields / Addition 


User_map.html - I'll probably be ok with this being HTML and just adding the switches? :shock: :D
Code: Select all
<!-- Load custom profile fields / Addition -->

<!--
 
<br /><br />
{
L_U_M_LOC}:<br />
{
user_map.UM_LOCATION}
<!--
 IF user_map.UM_LOCATION_DESC -- >
<
br /><br />
{
L_U_M_LOC_DESC}:<br />
{
user_map.UM_LOCATION_DESC}
<!--
 ENDIF -- >
 -->

<
br /><br />
{
user_map.UM_CPF_SHOW
volksdevil

Tiptop

Tiptop
 
Posts: 29
Joined: 08 Jul 2012, 20:16
 
Resolution: 1920x1080


Re: [DEV] jQ User Map api3

Postby 4seven » 10 Jul 2012, 15:58

a v.0.0.2 is on the way next days..
Current Mods | Mod Base | php(BB) programming | No help via PM
User avatar
4seven

Tiptop

Tiptop
 
Posts: 318
Joined: 20 Jun 2012, 16:55
 
Resolution: 1920x1080



Re: [DEV] jQ User Map api3 / Addition I v.0.0.2

Postby 4seven » 10 Jul 2012, 19:44

Outdated Version

Load custom profile fields / Addition I v.0.0.2

Now you can fully customize all available CPFs with template switches

Note: This Addition is tested and added to demo

Instruction

open

user_weather/user_map.php

find

Code: Select all
    if (!function_exists('get_user_avatar'))
    {
    include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
    }


after add

Code: Select all
            // Load custom profile fields / Addition
            include_once($phpbb_root_path . 'includes/functions_profile_fields.' . $phpEx);    
            
            
// Grab all profile fields from users in id cache for later use
            $cp = new custom_profile();    
            $profile_fields_cache 
= $cp->generate_profile_fields_template('grab', $user_id_array);
            // Save from following SQL:  , user_map_location, user_map_location_desc
            // Load custom profile fields / Addition                     


find and delete

Code: Select all
, user_map_location, user_map_location_desc


find

Code: Select all
        $row_username  = utf8_encode(urlencode($row['username']));


after add

Code: Select all
            // Load custom profile fields / Addition
            $cp_row    = $cp->generate_profile_fields_template('show', false, $profile_fields_cache[$row['user_id']]);
            // Load custom profile fields / Addition              


find

Code: Select all
            'UM_LOCATION'      => ucwords(str_replace('_', ' ', $row['user_map_location'])),
            'UM_LOCATION_DESC' => ($row['user_map_location_desc'] !== 0) ? $row['user_map_location_desc'] : false


replace with

Code: Select all
//  Load custom profile fields / Addition            
            // 'UM_LOCATION'      => ucwords(str_replace('_', ' ', $row['user_map_location'])),
            // 'UM_LOCATION_DESC' => ($row['user_map_location_desc'] !== 0) ? $row['user_map_location_desc'] : false    
//  Load custom profile fields            
# ----
'PROFILE_USER_MAP_WEATHER_NAME'  => (isset($cp_row['row']['PROFILE_USER_MAP_WEATHER_NAME'])) ? $cp_row['row']['PROFILE_USER_MAP_WEATHER_NAME'] : false,
'PROFILE_USER_MAP_WEATHER_VALUE' => (isset($cp_row['row']['PROFILE_USER_MAP_WEATHER_VALUE'])) ? $cp_row['row']['PROFILE_USER_MAP_WEATHER_VALUE'] : false,
# ----            
'PROFILE_USER_MAP_DESC_NAME'     => (isset($cp_row['row']['PROFILE_USER_MAP_DESC_NAME'])) ? $cp_row['row']['PROFILE_USER_MAP_DESC_NAME'] : false,
'PROFILE_USER_MAP_DESC_VALUE'    => (isset($cp_row['row']['PROFILE_USER_MAP_DESC_VALUE'])) ? $cp_row['row']['PROFILE_USER_MAP_DESC_VALUE'] : false,
# ----               


Explanation:

The General Syntax is always as in the Main jQ User Map api3 CPFs: PROFILE_YOUR_CPF_IDENT_NAME and PROFILE_YOUR_CPF_IDENT_VALUE

open

styles/prosilver/template/user_map.html

find

Code: Select all
<br /><br />
{
L_U_M_LOC}:<br />
{
user_map.UM_LOCATION}
<!--
 IF user_map.UM_LOCATION_DESC -->
<
br /><br />
{
L_U_M_LOC_DESC}:<br />
{
user_map.UM_LOCATION_DESC}
<!--
 ENDIF -->


replace with

Code: Select all
<!-- Load custom profile fields / Addition -->

<!--
 IF user_map.PROFILE_USER_MAP_WEATHER_NAME -->
<
br /><br />
{
user_map.PROFILE_USER_MAP_WEATHER_NAME}:
<
br />
{
user_map.PROFILE_USER_MAP_WEATHER_VALUE}
<!--
 ENDIF -->

<!--
 IF user_map.PROFILE_USER_MAP_DESC_NAME -->
<
br /><br />
{
user_map.PROFILE_USER_MAP_DESC_NAME}: 
<br />
{
user_map.PROFILE_USER_MAP_DESC_VALUE}
<!--
 ENDIF -->

<!--
 Load custom profile fields / Addition -->


Explanation:

The General Syntax is always as in the Main jQ User Map api3 CPFs:
{user_map.PROFILE_YOUR_CPF_IDENT_NAME} and {user_map.PROFILE_YOUR_CPF_IDENT_VALUE}.

As IF Syntax use just the _NAME <!-- IF user_map.PROFILE_YOUR_CPF_IDENT_NAME -->.
No S_WHATEVER Variable is needed.

Note: This adds some more SQL to user_map.php

---------------------------------------------------------------------

@ Volksdevil. Btw. you've done a good job on your user_map customization/styling.
Current Mods | Mod Base | php(BB) programming | No help via PM
User avatar
4seven

Tiptop

Tiptop
 
Posts: 318
Joined: 20 Jun 2012, 16:55
 
Resolution: 1920x1080


Re: [DEV] jQ User Map api3

Postby volksdevil » 11 Jul 2012, 01:35

Thanks 4seven, that's a big compliment from yourself :D

I'm happy to keep testing on my live site, I always back up files before making changes.

To add the new edits above, do we first replace the original files? I'm guessing yes? Instead of editing what I currently have/your last edits.
volksdevil

Tiptop

Tiptop
 
Posts: 29
Joined: 08 Jul 2012, 20:16
 
Resolution: 1920x1080


Re: [DEV] jQ User Map api3

Postby 4seven » 11 Jul 2012, 08:57

volksdevil wrote:To add the new edits above, do we first replace the original files? I'm guessing yes?

Yes. Reverse the install instruction from Addition v.0.0.1 and install Addition v.0.0.2. The Base is the main mod.
Current Mods | Mod Base | php(BB) programming | No help via PM
User avatar
4seven

Tiptop

Tiptop
 
Posts: 318
Joined: 20 Jun 2012, 16:55
 
Resolution: 1920x1080


Re: [DEV] jQ User Map api3

Postby javiexin » 11 Jul 2012, 12:09

4_seven, I hope you do not mind that I propose a little enhancement over your code. This small change will allow anyone to use ALL CPFs (not just the USER_MAP_WEATHER and USER_MAP_DESC CPFs) within the template, without any change to the PHP file; and besides, the code changes are even simpler.

What I would propose is to add the following code:
Code: Select all
    if (isset($cp_row['row']) && sizeof($cp_row['row']))
    {
        
$memberrow array_merge($memberrow$cp_row['row']);
    } 

replacing $memberrow (in both places in the above code) with the name of the array that you use in the call to $template->assign_block_vars('user_map', $memberrow);, and place that code directly before this assign_block_vars call. Sorry I cannot be more specific, I do not have the full code form the mod at hand, so I used the equivalent from memberlist.php.

This way, if you create a new CPF that you want to show in the map, you would only need to change the template, not the PHP file; with 4_seven's approach, you would need to change both the PHP and template to use the new CPF. Note that new CPFs will NOT appear automatically in the map, you will need to edit the template.

With this change, you would not need the code in the last edit in the PHP file that 4_seven presented above (just delete that code, as it would be redundant), and the correct code for your template would be the following:
Code: Select all
<!-- Load custom profile fields / Addition -->

<!-- IF user_map.S_PROFILE_USER_MAP_WEATHER -->
<br /><br />
{user_map.PROFILE_USER_MAP_WEATHER_NAME}:
<br />
{user_map.PROFILE_USER_MAP_WEATHER_VALUE}
<!-- ENDIF -->

<!-- IF user_map.S_PROFILE_USER_MAP_DESC -->
<br /><br />
{user_map.PROFILE_USER_MAP_DESC_NAME}:
<br />
{user_map.PROFILE_USER_MAP_DESC_VALUE}
<!-- ENDIF -->

<!-- Load custom profile fields / Addition -->


Again, not trying to correct you 4_seven (your code works just fine), but trying to make the code even better and more in line with what Volksdevil asked for.
By the way, this does NOT add any SQL over the code proposed by 4_seven, only a few array entries.

Hope this helps, best regards,
-javiexin
javiexin

Tiptop

Tiptop
 
Posts: 8
Joined: 26 Jun 2012, 12:56
 
Resolution: 1600x898


Re: [DEV] jQ User Map api3

Postby 4seven » 11 Jul 2012, 12:42

javiexin wrote:4_seven, I hope you do not mind that I propose a little enhancement over your code. This small change will allow anyone to use ALL CPFs (not just the USER_MAP_WEATHER and USER_MAP_DESC CPFs) within the template, without any change to the PHP file; and besides, the code changes are even simpler.


False. You can use each cpf with that, as i mentioned in the last instruction.

PHP

Explanation:

The General Syntax is always as in the Main jQ User Map api3 CPFs: PROFILE_YOUR_CPF_IDENT_NAME and PROFILE_YOUR_CPF_IDENT_VALUE

----------------------------

TEMPLATE

Explanation:

The General Syntax is always as in the Main jQ User Map api3 CPFs:
{user_map.PROFILE_YOUR_CPF_IDENT_NAME} and {user_map.PROFILE_YOUR_CPF_IDENT_VALUE}.

As IF Syntax use just the _NAME <!-- IF user_map.PROFILE_YOUR_CPF_IDENT_NAME -->.
No S_WHATEVER Variable is needed.


Means, you can use each ident, This was only an example for the main user map cpfs.
This works perfect now, exactly as you mentioned before. Flexibility.

By the way, this does NOT add any SQL over the code proposed by 4_seven, only a few array entries.


This adds ~5 more SQL request as without CPF System
Current Mods | Mod Base | php(BB) programming | No help via PM
User avatar
4seven

Tiptop

Tiptop
 
Posts: 318
Joined: 20 Jun 2012, 16:55
 
Resolution: 1920x1080


Re: [DEV] jQ User Map api3

Postby javiexin » 11 Jul 2012, 12:55

Sorry, 4_seven, but with the code of AddOn v0.0.2 you cannot use more CPFs than USER_MAP_WEATHER or USER_MAP_DESC, unless you change the PHP file.
javiexin wrote:This small change will allow anyone to use ALL CPFs ... within the template, without any change to the PHP file


If you want to use more CPFs with your code, you would have to ADD code in the assign_vars array per each CPF that you want to use in the template, similar to:
Code: Select all
'PROFILE_YOUR_CPF_IDENT_NAME'  => (isset($cp_row['row']['PROFILE_YOUR_CPF_IDENT_NAME'])) ? $cp_row['row']['PROFILE_YOUR_CPF_IDENT_NAME'] : false,
'PROFILE_YOUR_CPF_IDENT_VALUE' => (isset($cp_row['row']['PROFILE_YOUR_CPF_IDENT_VALUE'])) ? $cp_row['row']['PROFILE_YOUR_CPF_IDENT_VALUE'] : false

Else, these variables will not be available outside of the PHP file, as they are not sent to the template.

With the change I am proposing, you would NOT need to add anything in the PHP file to have ALL CPFs available in the template.
I hope you understand what I am trying to say.
-javiexin
javiexin

Tiptop

Tiptop
 
Posts: 8
Joined: 26 Jun 2012, 12:56
 
Resolution: 1600x898

PreviousNext

Return to Support Forum

Who is online

Users browsing this forum: No registered users and 1 guest

cron