Purify the content of a bio

melo lobo Posted in Beginning Developers 10 months ago

Hello Michael,
Can you help me purify the content of a Bio (display it in a readable and clear way). I use this code:

     $user = ossn_user_by_username($params['item']->username);
    $bio_content = ossn_call_hook('textarea', 'purify', false, $user->bio);
    $bio_content = ossn_call_hook('textarea', 'responsify', false, $bio_content); 
    $params['user']->bio = $bio_content;
    $content = ossn_plugin_view('profile/bio', $params);

but it gives me the following error

Error: Attempt to assign property "bio" on null in C:\xampp\htdocs\ossn\components\bio\plugins\default\bio\list\all_bios_item.php:29
Stack trace:
#0 C:\xampp\htdocs\ossn\libraries\ossn.lib.views.php(27): include()
#1 C:\xampp\htdocs\ossn\libraries\ossn.lib.views.php(50): ossn_include('C:/xampp/htdocs...', Array)
#2 C:\xampp\htdocs\ossn\libraries\ossn.lib.plugins.php(75): ossn_view('C:/xampp/htdocs...', Array)
#3 C:\xampp\htdocs\ossn\components\bio\plugins\default\bio\pages\search_results.php(20): ossn_plugin_view('bio/list/all_bi...', Array)
#4 C:\xampp\htdocs\ossn\libraries\ossn.lib.views.php(27): include('C:\\xampp\\htdocs...')
#5 C:\xampp\htdocs\ossn\libraries\ossn.lib.views.php(50): ossn_include('C:/xampp/htdocs...', Array)
#6 C:\xampp\htdocs\ossn\libraries\ossn.lib.plugins.php(75): ossn_view('C:/xampp/htdocs...', Array)
#7 C:\xampp\htdocs\ossn\components\bio\ossn_com.php(143): ossn_plugin_view('bio/pages/searc...', Array)
#8 C:\xampp\htdocs\ossn\libraries\ossn.lib.system.php(223): com_bio_search_bios_handler('search', 'type:bio', NULL, Array)
#9 C:\xampp\htdocs\ossn\components\OssnSearch\ossn_com.php(46): ossn_call_hook('search', 'type:bio', Array)
#10 C:\xampp\htdocs\ossn\libraries\ossn.lib.page.php(79): ossn_search_page(Array, 'search')
#11 C:\xampp\htdocs\ossn\index.php(22): ossn_load_page('search', Array)
#12 {main}

Probleme line is

$params['user']->bio = $bio_content;

THANKS

Replies
ma Melo lobo Replied 10 months ago

it's good, I solved the problem, the solution is to change $params['user']->bio = $bio_content to $user->bio = $bio_content. thank you for the interest you have shown

German Michael Zülsdorff Replied 10 months ago

Hmm ... I don't know how you expect us to understand what's going wrong with providing just 4 lines of code without any context?
At first siight it looks like you were talking about my components\bio\plugins\default\bio\list\all_bios_item.php file.
On the other hand this one has no line #29
And the more important part: It has no $params['user'] containing an object you could assign something to.
So maybe you're talking about a different file.
Anyway, you can't assign something to an object if that object doesn't exist at all. Thus - and in order to fulfill the requirement of the profile/bio plugin you need to create an instance of that object first like

$params['user'] = new stdClass();

See User contributes notes in https://www.php.net/manual/en/class.stdclass.php

Indonesian Arsalan Shah Replied 10 months ago

Bio content is purified by default. This error means user doesn't exists that you are trying to assign bio on.