Nifa
Hoi Peter,
Sorry, I find it hard to explain, but will give it another try.
For example, I want to use this API
www.joomlapolis.com/documentation/279-co...hrough-getfields-api
in a module using Sourcerer->PHP.
The last line of the page above gives exact what I want.
$avatar = $cbUser->getField( 'avatar', null, 'html', 'none', 'list' );
It returns a full HTML enriched avatar code, if avatar is available or else a nice SVG code, for examples see below.
1. For users with an uploaded avatar, the $avatar value will return something like:
<img src="https://mywebsite.nl/images/comprofiler/tn1737_62e7f1d8785a7.jpg" alt="Deelnemer 1" title="Deelnemer 1" class="cbImgPict cbThumbPict img-thumbnail cbImgAvatar">
2. For users, for example Peter van Western, with no avatar the API will return a svg-code with their initials:
<svg viewBox="0 0 100 100" class="cbImgPict cbImgPictInitial cbThumbPict img-thumbnail cbImgAvatar"><rect fill="#6C007F" width="100" height="100" cx="50" cy="50" r="50"></rect><text x="50%" y="50%" style="color: #ffffff; line-height: 1;" alignment-baseline="middle" text-anchor="middle" font-size="40" font-weight="600" dy="0.1em" dominant-baseline="middle" fill="#ffffff">PW</text></svg>
The code runs without error. PHP test gives in all cases $avatar is not empty. However, in first case (echo $avatar;) gives no output at all and in the second case it only echo users initials (here PW) as that is the only value that is not inside any <>.
I know from experience that sourcerer can remove everything within any <>, and I think this is the reason why I cannot use the API output within Sourcerer.
The API call seems to work fine because when I choose raw output, which doesn't contain any <> it gives the expected output
For example:
$avatar = $cbUser->getField( 'avatar', false, false );
Which gives for users with an avatar set the URL of that avatar image file. But this doesn't create the SVG for all users without an avatar. That is one of the reassons why I really want to use the full HTML CB API call.
In answer to your last question, the essential code part:
{source}
<?php
global $_CB_framework;
$db =& JFactory::getDBO();
$query = 'SELECT user_id from #__comprofiler limit 3';
$db->setQuery($query);
$result = $db->query();
while($row = mysqli_fetch_assoc( $result ))
{
$cbUser = CBuser::getInstance($row['user_id'], false );
$avatar = $cbUser->getField( 'avatar', null, 'html', 'none', 'list' );
echo $avatar ;
?>
{/source}
I hope you can help.
With kind regards, Nico