Calling a file to execute

elgg_push_context('widgets');
 
$title = elgg_view('output/url', array(
'href' => "/celebrations/celebrations",
'text' => elgg_echo('Aniversariantes'),
'is_trusted' => true,
));
 
Bold is the file code.
 
//filtered users
$filterid = (int) $vars['entity']->todayfilterid;
if (!$filterid){
$filterid = 0;
}
 
print '<div class="user_settings"><p style="text-align:right">'.elgg_echo('today_celebrations:today').' <strong>'.printcelebrationsdate(1, time()).'</strong></p>';
 
$row_celebrations = user_celebrations(0,'next', $filterid);
 
// list of celebrations
if (!empty($row_celebrations)) {
print '<table width="100%">';
 
foreach($row_celebrations as $key => $val) {
$sendcelebrationsmessage = '';
if (($val['type'] != 'dieday') && ($val['id'] != elgg_get_logged_in_user_guid())) {
$sendcelebrationsmessage = '<a class="privatemessages" href="'.elgg_get_site_url().'messages/compose?send_to='.$val['id'].'" >&nbsp;</a>';
}
if ((elgg_get_plugin_setting("replaceage","celebrations") == 'yes') && ($val['type'] == 'birthdate')){
$age = showage($val['date']).' '.elgg_echo('celebrations:age');
} else {
$age = '';
}
$even_odd = ( 'F3F3F3' != $even_odd ) ? 'F3F3F3' : 'FFFFFF';
echo "<tr bgcolor=\"#{$even_odd}\">";
print '<td><img class="user_mini_avatar" src="'.$val['icon'].'"> <a href="'.$val['url'].'" title="'.$val['fullname'].'">'.$val['name'].'</a></td><td align="right">'.elgg_echo('today_celebrations:'.$val['type']).'</td><td align="right">'.$age.'</td><td align="right">'.$sendcelebrationsmessage.'</td></tr>';
}
print '</table>';
 
 
print '</div>';
 
 
if ($row_celebrations) {
echo elgg_view_module('featured', $title, 'HERE');
} else {
print "<p>".elgg_echo('today_celebrations:nocelebrations')."</p>";
}
 
} else {
$row_celebrations = elgg_echo('nothing');
echo elgg_view_module('featured', $title, 'HERE');
}
 
I wanted to call the execution of a file or code where it is marked "HERE".
 

 
  • The third parameter of elgg_view_module() must contain already the content you want to output. The third parameter is not meant to refer to a view / file that deals with the output.

    Just assign the output of the print commands to a variable and then use this variable as 3rd parameter, i.e.

    $body = "some output"; // the rest after a print command
    
    $body .= "some other print output";
    
    echo elgg_view_module('featured', $title, $body);

    You just need to make sure to assign all print output to the variable.

  • Thank you Master iionly for the tip. But then I need to put the whole line of code below for the third parameter. How to associate this whole line in a variable? In case it would be $ body 
    Because that code below would be the third parameter
     
    
     

     

     

    //filtered users
    $filterid = (int) $vars['entity']->todayfilterid;
    if (!$filterid){
    $filterid = 0;
    }
     
    print '<div class="user_settings"><p style="text-align:right">'.elgg_echo('today_celebrations:today').' <strong>'.printcelebrationsdate(1, time()).'</strong></p>';
     
    $row_celebrations = user_celebrations(0,'next', $filterid);
     
    // list of celebrations
    if (!empty($row_celebrations)) {
    print '<table width="100%">';
     
    foreach($row_celebrations as $key => $val) {
    $sendcelebrationsmessage = '';
    if (($val['type'] != 'dieday') && ($val['id'] != elgg_get_logged_in_user_guid())) {
    $sendcelebrationsmessage = '<a class="privatemessages" href="'.elgg_get_site_url().'messages/compose?send_to='.$val['id'].'" >&nbsp;</a>';
    }
    if ((elgg_get_plugin_setting("replaceage","celebrations") == 'yes') && ($val['type'] == 'birthdate')){
    $age = showage($val['date']).' '.elgg_echo('celebrations:age');
    } else {
    $age = '';
    }
    $even_odd = ( 'F3F3F3' != $even_odd ) ? 'F3F3F3' : 'FFFFFF';
    echo "<tr bgcolor=\"#{$even_odd}\">";
    print '<td><img class="user_mini_avatar" src="'.$val['icon'].'"> <a href="'.$val['url'].'" title="'.$val['fullname'].'">'.$val['name'].'</a></td><td align="right">'.elgg_echo('today_celebrations:'.$val['type']).'</td><td align="right">'.$age.'</td><td align="right">'.$sendcelebrationsmessage.'</td></tr>';
    }
    print '</table>';
     
     
    print '</div>';

     

     

     

     

     

     
    
     
  • It's not the whole code but only the output produced by this code that you need to assign to a variable that you then use as 3rd parameter. The whole code needs to be added in the file you also have the elgg_view_module() line with changing the direct output of the code (here the print command is used for output), e.g.

    print '<table width="100%">';

    becomes

    $body = '<table width="100%">';

    For the second and consecutive outputs you would have to use .= instead of = to append the output to the value already assigned to $body.

    You also need to define the values taken from the $vars variable directly here. In the celebrations plugin the $vars array values are set elsewhere already when the code is called. You can't rely on that anymore.

    If you wouldn't want to add the whole code here, you could add a new view file (widget view files won't work though) and then call this view with elgg_view(), e.g.

    $body = elgg_view('where/the/view/is', vars());

    In this case you would still have to set the values used in the $vars array in the view but the code would not have to get changed (because elgg_view() return the output and saves in in $body that you can then use for elgg_view_module()).

  • Trying to master but nothing yet. I want to call plugin celebration on my main page, just like I called blogs, events ... except that in these plugins I was able to identify type and subtype. Today's birthday I can not call. Below is the format I call blogs, events ...
    
    $ Options = array (
    'Type' => 'birthdate',
    // 'subtype' => 'birthdate',
    'Full_view' => false,
    'Pagination' => false,
    'Subtitle' => $ date,
    'Limit' => $ num,
    'List_type' => 'gallery',
    );
    
    
    $ Row_celebrations = elgg_get_entities ($ options);
    
    Up $ row_celebrations would be the third parameter. But in celebrations this method does not work.
    this method does not work.
  • The Celebrations plugin needs some custom code to retrieve the celebration entities, so the way it works for other entities won't work. Also, listing is done in a custom way.

    Assuming you use Elgg 1.8 (as newer releases of the Celebrations plugin no longer use the "print" command) the code would be

    $body = '<div class="user_settings"><p style="text-align:right">'.elgg_echo('today_celebrations:today').' <strong>'.printcelebrationsdate(1, time()).'</strong></p>';
    
    $row_celebrations = user_celebrations(0,'next', 0);
    
    // list of celebrations
    if (!empty($row_celebrations)) {
        $body .= '<table width="100%">';
    
        foreach($row_celebrations as $key => $val) {
            $sendcelebrationsmessage = '';
            if (($val['type'] != 'dieday') && ($val['id'] != elgg_get_logged_in_user_guid())) {
                $sendcelebrationsmessage = '<a class="privatemessages" href="'.elgg_get_site_url().'messages/compose?send_to='.$val['id'].'" >&nbsp;</a>';
            }
            if ((elgg_get_plugin_setting("replaceage","celebrations") == 'yes') && ($val['type'] == 'birthdate')){
                $age = showage($val['date']).' '.elgg_echo('celebrations:age');
            } else {
                $age = '';
            }
            $even_odd = ( 'F3F3F3' != $even_odd ) ? 'F3F3F3' : 'FFFFFF';
            echo "<tr bgcolor=\"#{$even_odd}\">";
            $body .= '<td><img class="user_mini_avatar" src="'.$val['icon'].'"> <a href="'.$val['url'].'" title="'.$val['fullname'].'">'.$val['name'].'</a></td><td align="right">'.elgg_echo('today_celebrations:'.$val['type']).'</td><td align="right">'.$age.'</td><td align="right">'.$sendcelebrationsmessage.'</td></tr>';
        }
        $body .= '</table>';
    } else {
        $body .= "<p>".elgg_echo('today_celebrations:nocelebrations')."</p>";
    }
    $body .= '</div>';
    
    echo elgg_view_module('featured', elgg_echo('today_celebrations:title'), $body);

    That's the code also used in mod/celebrations/views/default/widgets/index_today_celebrations/content.php (which offers an index page widget if the Widget Manager plugin is installed). The only changes necessary are the points I already outlined in my previous postings.

  • Thank you Master Iionly for the help. I broke my head but I did it. $ Result. = '<Table width = "100%">';
    $ Result. = Print '</ table>'; Thank you very much! Learning more and more!
Beginning Developers

Beginning Developers

This space is for newcomers, who wish to build a new plugin or to customize an existing one to their liking