Needing help with a component being developed.

Allon Prooit Posted in Component Development 10 months ago

I am needing to create a widget on the user profile page that shows basic info like the Bio component does on a subpage. Right now I have a nearly completed component that does everything but port the info into a widget for the profile page. Can anyone help me with this?

Replies
us Allon Prooit Replied 10 months ago

You are correct sir! Sorry about that. I have fixed it and uploaded a new file. I changed $modules to $return.

German Michael Zülsdorff Replied 10 months ago

Yes, it's working ... at first sight.
But there's something really wrong that will cause bad side effects:
1.
Your original function (you posted here) reads:

function com_intro_widget_hook($hook, $type, $return, $params) {

and this one is correctly returning

return $return;

while in your component the function reads:

function com_intro_widget_hook($hook, $type, $modules, $params) {

but you're still using the former code that is returning $return.

us Allon Prooit Replied 10 months ago
us Allon Prooit Replied 10 months ago

Boom! It works!!! Had to pull out a few lines of exorbitant code and make it look a bit more like the first function to get it to go. Will have it posted as a new component shortly!

German Michael Zülsdorff Replied 10 months ago

Yes.
In the beginning you got the original intro data via $params['user']->intro
Next, you passed it to textarea's purifier which returned it as $intro_content
Next, you passed $intro_content to textarea's responsifier which returned it as $intro_content
Thus $intro_content indeed is the finalized intro data ready for being passed to your profile widget.

us Allon Prooit Replied 10 months ago

Ok so, should it be $intro_content instead?

German Michael Zülsdorff Replied 10 months ago

Name it as you want, at least with your current code it makes no sense because you don't pass it to the profile/widget plugin. You're passing the $display array instead.

So let's have a closer look into that.

$display['content'] = $content;

I can't find any initialization of $content in your function and I'm sure there's a PHP warning like ""Undefined variable $content" in file ...." in your error log.

us Allon Prooit Replied 10 months ago

It was an appeal to redundancy. The question, how do we make the function port like the first function? I was just trying to replicate it.

German Michael Zülsdorff Replied 10 months ago

Okay, so let's have a look into your com_intro_widget_hook function:
Being called, it retrieves a complete User object with its attributes via $params['user']
And if all conditions are met the original $params['user']->intro data is passed to two post-processing hooks and in the end the processed intro data is stored in $intro_content.
Things are getting strange with the next line, though:

$params['user']->intro = $intro_content;

Why are you overwriting the original data with the processed data? Even more since $params['user'] is no longer used in the following lines?

us Allon Prooit Replied 10 months ago

Fairly sure the issue lies here...
The first function ports the Intro into a subpage (works great).
The second function should port the Intro into a widget (works some).
Any thoughts?

    function com_intro_profile_intro_page($hook, $type, $return, $params)
{
    $page = $params['subpage'];
    if ($page == 'intro' && isset($params['user']->intro)) {
        if (!isset($params['user']->intro_access) || (isset($params['user']->intro_access) && $params['user']->intro_access == OSSN_PUBLIC || ($params['user']->intro_access == OSSN_FRIENDS && ossn_isLoggedin() && ossn_loggedin_user()->isFriend(ossn_loggedin_user()->guid, $params['user']->guid)) || (ossn_isLoggedin() && ossn_loggedin_user()->guid == $params['user']->guid) || ossn_isAdminLoggedin())     ) {
            $intro_content = ossn_call_hook('textarea', 'purify', false, $params['user']->intro);
            $intro_content = ossn_call_hook('textarea', 'responsify', false, $intro_content); 
            $params['user']->intro = $intro_content;
            $content = ossn_plugin_view('profile/intro', $params);
            echo ossn_set_page_layout('module', array(
                'title' => ossn_print('com:intro:pagetitle'),
                'content' => $content
            ));
        }
    }
}
function com_intro_widget_hook($hook, $type, $return, $params) {
    if (!isset($params['user']->intro_access) || (isset($params['user']->intro_access) && $params['user']->intro_access == OSSN_PUBLIC || ($params['user']->intro_access == OSSN_FRIENDS && ossn_isLoggedin() && ossn_loggedin_user()->isFriend(ossn_loggedin_user()->guid, $params['user']->guid)) || (ossn_isLoggedin() && ossn_loggedin_user()->guid == $params['user']->guid) || ossn_isAdminLoggedin())     ) {
        $intro_content = ossn_call_hook('textarea', 'purify', false, $params['user']->intro);
        $intro_content = ossn_call_hook('textarea', 'responsify', false, $intro_content); 
        $params['user']->intro = $intro_content;
        $display = array();
        $display['content'] = $content;
        $content = ossn_plugin_view('profile/widget', $display);
        $return[] = $content;
    }
    return $return;
}