Profile content bot

17 years 11 months ago #14352 by CoBPEZ
Profile content bot was created by CoBPEZ
Hello,

I have written a simple content mambot for home.clanofbobs.org . All it does is turning Wiki link text to links to a wiki that's tightly associated the site. Now i would like for text in the CB user profile to be processed the same way. I've tried to see if CB allows me to tell it to run profile content through the joomla content bots. It doesn't seem so. So I'm thinking I could write a CB plugin for it. I've read the API docs and it mentions
  • user bots
  • function onBeforeUserProfileDisplay ($user, $ui, $cbUserIsModerator, $cbMyIsModerator)
But I'm still quite clueless on how to go about with this. Anyone knows where I can find more info or an example user bot or just whatever? I'd greatly appreciate it!

/PEZ - Stay excellent to each other

Please Log in to join the conversation.

17 years 11 months ago #14992 by CoBPEZ
Replied by CoBPEZ on topic Re:Profile content bot
Sorry for bumping this. But I would really like to get at least a pointer. Even a "no, that's not possible" would help me. Or if my question is unclear I want to know that too so that I can try rephrase it.

/PEZ - Stay excellent to each other

Please Log in to join the conversation.

17 years 11 months ago #15009 by trail
Replied by trail on topic Re:Profile content bot
I am not the expert on this. but as you have found that plugin trigger. it seems to me that data resides in $user->cbfield

i think al you would have to do is change that data in your plugin for that php session. and when the output time comes, your changed data is used. i guess.

i suggest you just start, that always works for me when things seem difficult. tinker around and you will most probably find your way.

DJ Trail.
CB Co-Founder & Test-Lead.
Plugins: My Age , Starsign Matchmaking Horoscope , My Visitor , My Highscores , My ProfileID ,
My Components: Import & Invite Karma Casino (Use Test / Test)
My Modules: Many :)

Please Log in to join the conversation.

17 years 11 months ago #15136 by CoBPEZ
Replied by CoBPEZ on topic Re:Profile content bot
Indeed, but I was fully clueless. I reread the API doc though and now I have some more clues. From what I can see there is no way to do what I want:

I want to filter all output displayed on my joomla site through a wiki-linker that looks for text like Some term and replaces that with links to wiki articles on a related wiki site.

I have made a mambot that does this for regular joomla content. But then I noticed that this mambot doesn't get to handle the output from cb. Thus it seemed like a cb userbot is needed. From this little experiment:

[code:1]
<?php
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

$_PLUGINS->registerFunction('onBeforeUserProfileDisplay', 'do_halowikilinking');

/**
* halowiki.net linking in user profile
* @package Community Builder
* @author Peter Strömberg - PEZ - pezius@gmail.com
*/
function do_halowikilinking ($user, $ui, $cbUserIsModerator, $cbMyIsModerator) {
print("<pre>"«»);
print_r($user);
print("</pre>"«»);
$user->cb_aboutme = "foo";
}
?>
[/code:1]

I see that I am able to alter the data in cb fields before they are displayed. But I'm not given a chance to alter other data. Like the data in the profile book. I want users to be able to assume all content they add to the site will be subject to wiki linking.

Any ideas anyone?

Post edited by: CoBPEZ, at: 2006/06/12 14:34

/PEZ - Stay excellent to each other

Please Log in to join the conversation.

17 years 11 months ago #15198 by CoBPEZ
Replied by CoBPEZ on topic Re:Profile content bot
I though maybe someone might be interested in the working version of this userbot. Even if others might not want to do wiki linking this is the gist of a userbot. Here goes:

[code:1]
<?php
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

$_PLUGINS->registerFunction('onBeforeUserProfileDisplay', 'do_halowikilinking');

/**
* halowiki.net linking in user profile
* @package Community Builder
* @author Peter Strömberg - PEZ - pezius@gmail.com
*/
function do_halowikilinking ($user, $ui, $cbUserIsModerator, $cbMyIsModerator) { // ui=1 front, ui=2 backend, 2* boolean
foreach ($user as $field => $value) {
$user->$field = preg_replace_callback("#\[\[(.*?)\]\]#s", 'bothalowiki_replacer', $value);
}
}

/**
* Replaces the WikiTagged words
* @return Wikilinked words
*/
function bothalowiki_replacer(&$matches) {
$result = split('\|', $matches[1]);
if (empty($result[1])) {
$result[1] = $result[0];
}
return '<a href="halowiki.net/wiki/'.$result[0].'" title="halowiki.net: '.$result[0].'" target="halowiki.net">'.$result[1].'</a>';
}
?>
[/code:1]

As should be obvious from the code this only works on Cb fields, all other data in the profile will remain untouched.

Possible uses of this kind of bot includes working on a specific field, be it a cb defined or user defined one. Birthday countdowns anyone?

I have sort of given up on trying to make some global joomla content bot/hack. I realized all components would need a plugin/hack for it to work as I want. Maybe some future version of joomla will make this task more realistic.

/PEZ - Stay excellent to each other

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.188 seconds

Facebook Twitter LinkedIn