Forum Activity for @tig

TiG
@tig
02 Sep 2019 10:49:44PM
140 posts

Converting Visitor to Member


Jamroom Developers

Okay, thanks Michael.
TiG
@tig
02 Sep 2019 10:24:16AM
140 posts

Converting Visitor to Member


Jamroom Developers

We are planning to build a module that caters to site visitors and makes it extremely easy for them to become members.

The first step is to find the best way to intercept a visitor accessing the site. The 'session_started' listeners are invoked multiple times on a single HTTP message from a single visitor (e.g. press F5 and the jrUser listener is invoked repeatedly). This leads me to think that this event is not the proper spot to insert a visitor conversion UI.

If there is an ideal spot to detect a visitor's first access of the site (the initiation of a visitor session) so that we can offer them a convenient conversion to member I would appreciate the insight.
TiG
@tig
15 Jan 2019 08:23:13PM
140 posts

Moving a media image file


Jamroom Developers

Michael

It is amazing what you know of JR. Will locate this module and follow its lead.

Thanks!,
TiG
TiG
@tig
15 Jan 2019 03:30:16PM
140 posts

Moving a media image file


Jamroom Developers

We have a need to move an image media file from one profile to another. The ideal function would be a rename because there is no functional need to read and write the file - just to literally change the hosting profile.

Basically I want like to build a function like jrCore_rename_media_file($profile_id, $current_name, $new_name); but with a $from_profile_id and a $to_profile_id parameter instead of simply $profile_id.

My concern is twofold:

1. Want to avoid reading and writing the image file if possible (no need to consume the needed resources)
2. Want to implement a future-proof solution. That is, to avoid accessing volatile functions.

How would you recommend I approach this problem?
updated by @tig: 20 Apr 2019 12:05:59PM
TiG
@tig
01 Jan 2019 08:22:37AM
140 posts

new value


Jamroom Developers

Brian

I agree, this is a hack but it is fail-safe. The worst case scenario is to wind up where I was. So I went ahead and implemented it. Hopefully this addresses the confusion.

To implement, I introduced a bit more surgical code that focuses on a specific field and works even if the user has customized the label. In case others wish to use this method, here is the operative function (ntCore is the the core for NT modules):

/**
 * Change the default 'new value' label to $label in a 'select_and_text' field with id of $field
 * @param  string - $content - the HTML content of a form to be displayed
 * @param  string - $field - the id of the subject 'select_and_text' field
 * @param  string - $label - the new label to replace the default of 'new value'
 * @return string - the modified content (original content if no modification made)
 */
function ntCore_relabel_new_value_field($content,$field,$label)
{ $signature = 'id="' . $field . '_select"'; // signature for field if (strpos($content, $signature) >= 0) // avoid unnecessary preg { $_ln = jrUser_load_lang_strings(); $target = $_ln['jrCore'][48]; // current label to replace $pattern = '~(.+' . $signature . '.+form_select_and_text_tag">)(' . $target . ')(<.*)~s'; $replace = '$1' . $label . '$3'; $new_content = preg_replace($pattern,$replace,$content,1); return $new_content ? $new_content : $content; } else return $content; }

Thanks again for providing critical info for me to make progress.

Happy New Year,
TiG
TiG
@tig
31 Dec 2018 01:10:46PM
140 posts

new value


Jamroom Developers

The select_and_text form field type provides a box for the user to enter a custom value. This box is always labeled 'new value' (or what is placed in lang [48]).

I would like to provide a more descriptive label (one that varies per instance) to mitigate user confusion. There does not seem to be any way to accomplish this (other than to create a new field type).

Anyone know of a way to adjust the 'new value' label per instance?
updated by @tig: 08 Apr 2019 10:34:58PM
TiG
@tig
01 Dec 2018 09:36:25AM
140 posts

Dynamically changing $_user quota settings


Jamroom Developers

Michael

Tweaking using db_get_item appears to cover the bases. Not sure why (difficult to actually trace this to know precisely why this works) but if it works it works, right?

For completeness, here are some details per your last note:

Quote: jrProfile_get_quota() doesnt look like it touches $_user.

jrProfile_get_quota() does indeed not touch $_user but it is called by functions which assign its return array to $_user. So basically one could effect the desired change within jrProfile_get_quota. The following code does indeed accomplish the effect (see @@@):

    $tb1 = jrCore_db_table_name('jrProfile', 'quota_setting');
    $tb2 = jrCore_db_table_name('jrProfile', 'quota_value');
    $req = "SELECT s.`module` AS m, s.`name` AS k, s.`default` AS d, v.`value` AS v FROM {$tb1} s LEFT JOIN {$tb2} v ON (v.`quota_id` = '{$quota_id}' AND v.`module` = s.`module` AND v.`name` = s.`name`)";
    $_rt = jrCore_db_query($req, 'NUMERIC');
    if (!isset($_rt) || !is_array($_rt)) {
        return false;
    }
    $_qt = array();
    foreach ($_rt as $_v) {
        $_qt["quota_{$_v['m']}_{$_v['k']}"] = (isset($_v['v']) && strlen($_v['v']) > 0) ? $_v['v'] : $_v['d'];
    }

    // @@@
    $_qt['quota_jrSmiley_allowed'] = 'off';
    // @@@

My challenge has been to find a way to effect this change with customer appropriate code.

Quote: ... so you'd be tweaking before it arrived at the session start.

The session_started listener did work great -changes applied and accepted into $_user- but was too early in the process. Myriad functions call jrProfile_get_quota() and overwrite the $_user quota fields. So tweaking things before the session start will not work.

But it appears I have a solution now so these other attempts are just history.

As always, I appreciate your insight and support. Thanks,
TiG
@tig
30 Nov 2018 08:02:44PM
140 posts

Dynamically changing $_user quota settings


Jamroom Developers

Michael

The session_started listener is an elegant method for accomplishing my intent. The change works fine but only for a short time. Trouble is, any change to $_user quota_ fields is overwritten later on by calls to jrProfile_get_quota() whose results are re-assigned to $_user.

Best I can tell the only way to dynamically override a quota field in $_user and make it stick is to do so within this function. I see no customer appropriate means to override a quota_ field in $_user that will survive long enough to have an effect.

Largely this is an FYI, but if anything else comes to mind please let me know.

Thanks,
TiG
@tig
29 Nov 2018 11:13:35PM
140 posts

Dynamically changing $_user quota settings


Jamroom Developers

Michael

Perfect! Thanks much for the help.
TiG
@tig
29 Nov 2018 11:01:25PM
140 posts

Dynamically changing $_user quota settings


Jamroom Developers

Hi Michael

What I am looking for is an event right after $_user is created (or updated) that would allow me to override fields such as $_user['quota_jrSmiley_active'] for a tiny minority of users.

Thanks
1