XF 2.1 Looking for help getting 3rd party PHP into Xenforo, have been trying for too long

Upgrayedd

Member
The links to a copy of the Lite.php file and the documentation are located at the bottom.

Ok I believe this might be a simple solution for a lot of people so I have held off for too long on seeking assistance.

I run a site with Xenforo and aMember (membership management software), and I would like to pull some data from there and put it inside of a page node. To do this, I am trying to find a proper way to get a standalone file that aMember provides that is called "Lite.php" to load on the page node so that I can use the functions, or least begin to learn more...but I'm at a standstill.

I've brought the file over into my src/Pages/ folder and given it the namespace and class, but that is about as far as I get. I run into one error and if I solve that, I run into the next. I believe that the issue may have a little so do with ~line 634 where it looks up the config for aMember. That error is because the path is relative to the add-on directory, which I can fix by putting a copy of the config in that folder but I'm pretty sure that isn't the right way and also doesn't solve the problem.

Any way, I would be greatly appreciated if anyone would be willing to take a look and help me out here.


----------------------------------------
Links to docs:

Directory structure:
  • Public_Html/
    • aMember/library/Am/Lite.php
----------------------------------------


I believe @sub_ubi might be of help here for me as well if they see this.
 
I'd open a ticket, alex & caesar are usually quick to respond.

There's also a forum you can ask on:

I'm well familiar with that, but knowing that Xenforo is the place it needs to integrate with....was hoping somebody might have some instruction. I will be checking in with them as well but figure this is something that XF devs would know better?
 
Late bump to this and meant to post sooner, but I was able to get a solution for this along with some general guidelines to pull other data if you wanted to.

Here is from the actual author:
The idea is simple:
1. Create new custom field in Xenforo
2. Sync some value to this field from aMember (code in site.php)
3. Display this custom field within template

(2) is not simple part actually and there is not common solution unfortunately.
Exact code depends on information that you want to sync.

Link to the solution for this: https://gist.github.com/cgi-caesar/b264df5e174add7818839c987b3685c7
PHP:
<?php

/**
 * You need to create custom user field within Xenforo admin interface
 * Users -> Custom user Fields
 *
 * Then you can use the following code to sync some data from aMember to Xenforo fields
 *
 * Then you can use the following syntax within Xenforo template to display this information:
 *
 * Subscriptions: {$xf.visitor.Profile.custom_fields.active_products}
 * Expire Date: {$xf.visitor.Profile.custom_fields.expire}
 */

Am_Di::getInstance()->hook->add(
    Am_Event::SUBSCRIPTION_ADDED,
    function (Am_Event $e) {
        $user = $e->getUser();
        $product_titles = implode(", ", $e->getDi()->productTable->getProductTitles($user->getActiveProductIds()));
        syncUserFieldToXf($user, 'active_products', $product_titles);
    });

Am_Di::getInstance()->hook->add([
        Am_Event::ACCESS_AFTER_UPDATE,
        Am_Event::ACCESS_AFTER_INSERT,
        Am_Event::ACCESS_AFTER_DELETE
    ],
    function (Am_Event $e) {
        /* @var User $user */
        $user = $e->getAccess()->getUser();
        $v = amDate($user->getExpire());
        syncUserFieldToXf($user, 'expire', $v);
    });

function syncUserFieldToXf(User $user, $fn, $v)
{
    $di = Am_Di::getInstance();

    if ($pl = $di->plugins_protect->loadGet('xenforo')) {
        $table = $pl->getTable();
        if ($visitor = $table->findByAmember($user)) {

            $table->getAdapter()->query(<<<CUT
                INSERT INTO xf_user_field_value (user_id, field_id, field_value) VALUES (?, ?, ?)
                    ON DUPLICATE KEY UPDATE field_value = VALUES(field_value)
CUT
                , $visitor->user_id, $fn, $v);

            $val = $table->getAdapter()->selectCell("SELECT custom_fields FROM xf_user_profile WHERE user_id=?", $visitor->user_id);
            $val = $val ? json_decode($val, true) : [];
            $val[$fn] = $v;
            $val = json_encode($val);
            $table->getAdapter()->query("UPDATE xf_user_profile SET custom_fields=? WHERE user_id=? LIMIT 1", $val, $visitor->user_id);
        }
    }
}
 
Back
Top Bottom