Extract with a jquery/js or ajax/php owner_page name, his friends name, utl of pages and icons

hi i'm a begginer in ELGG, so i have a question...i really need to know how to Extract with a jquery/js or ajax/php:
1)owner_page name,

2)his friends name,

3)url of pages and icons?

regards.Thanks

  • Shortly:

    1 - Register action and set some inputs, e.g.

    $user_guid = elgg_get_logged_in_user_guid();

    $user = get_user($user_guid);

    $name = $user->username;

    ..etc...

     

    2 - Create call

    var guid

    var user

    var name

    wzm.action('path_to/action', {
          data: {
            guid: guid,
            user: user,
            name: name,

    ...............
          },

    success: function(result, success, xhr){

               //your results here

    },

     

  • The page owner is supplied as a json object on every page

    elgg.page_owner // the object

    alert('Page owner is ' + elgg.page_owner.name);

     

    As mentioned for other info you'll need to create a callback/webservice or a view that loads it into each page.  Keep in mind a page owner isn't always an ElggUser

  • Thanks to all!

    This information handle me to go a little bit on in my plugin develop.

    However i have a new problem:

    I have correctly registered the action. my php file is linked with my javascript one and the are able to pass simple data like strings, number or boolean value...

    ...BUT: all elgg function that i call on my php file like

    $owner = elgg_get_logged_in_user_entity();

    $guid = elgg_get_logged_in_user_guid();

    $logged = elgg_is_logged_in();

    give a bad result . I explain.

    elgg_get_logged_in_user_entity(); ---> give NULL

    $guid = elgg_get_logged_in_user_guid(); ---> give 0

    $logged = elgg_is_logged_in(); ---> give false

    i think is a session problem. but i need that all those function must work for give back data to my js.

    it is a handler problem? How to declare it correctly ?? it's a session problem???

    thanks a lot for future answers.

     

     

  • @Arthy What's callback?

    $some_array = function(); //parameter

    return $some_array; //calls your parameter

    Sometimes, an example better of the words :)

    Look at this code

     

  • My fault. i use an echo into my php for sending back variables value. i'll post my code now.

    my js:

    elgg.action('friendsgallery/myfile.php',{

    dataType: "json",
    success: function(response){

    alert(response);
    console.log("Response: " +response);
    alert("Page Owner is: " +elgg.page_owner.name) ;
    alert("Page Owner Entity is: " +elgg.page_owner.guid);

    if(response){

    //do something

    }

    else{

    //error message

    }

    My php file is this:

    <?php

    require_once("/home/mydomain/public_html/engine/lib/elgglib.php");
    require_once("/home/mydomain/public_html/engine/lib/pageowner.php");
    require_once("/home/mydomain/public_html/engine/lib/output.php");
    require_once("/home/mydomain/public_html/engine/lib/configuration.php");
    require_once("/home/mydomain/public_html/engine/lib/sessions.php");

     

    $my_variabile="somevar";

    $owner = elgg_get_logged_in_user_entity();

    $guid = elgg_get_logged_in_user_guid();

    $logged = elgg_is_logged_in();

    echo json_encode($logged);

    ?>

    the problem is:

    if i send back to my js the variable $my_variable, there is no problem

    it works perfectly.

    but if i try to send the variables $owner, $guid or $logged, i have as result in my js response rispecrively:

    - NULL

    - 0

    - false

    and i do not understand why!!!

     

    thanks for answers.

  • You do not need this:

    require_once("/home/mydomain/public_html/engine/lib/elgglib.php");
    require_once("/home/mydomain/public_html/engine/lib/pageowner.php");
    require_once("/home/mydomain/public_html/engine/lib/output.php");
    require_once("/home/mydomain/public_html/engine/lib/configuration.php");
    require_once("/home/mydomain/public_html/engine/lib/sessions.php");

     

    If your action is properly registered.  If it isn't, then requiring these files isn't enough to properly boot the elgg system.

  • Elgg really does need an in depth documentations for this

  • You can boot elgg by 

    require_once("/home/mydomain/public_html/engine/start.php");

     

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