示例#1
0
function user_get_friends($username, $limit = 10, $offset = 0)
{
    ini_set('display_startup_errors', 1);
    ini_set('display_errors', 1);
    error_reporting(-1);
    if ($username) {
        $user = get_user_by_username($username);
    } else {
        $user = elgg_get_logged_in_user_entity();
    }
    if (!$user) {
        throw new InvalidParameterException(elgg_echo('registration:usernamenotvalid'));
    }
    $options = array('limit' => $limit, 'offset' => $offset);
    $friends = $user->getfriends($options, 10, 0);
    $friends = get_list_entities_from_relationship($friends);
    //return get_user_friends($user->guid, '' , $limit, $offset);
    if ($friends) {
        foreach ($friends as $single) {
            $friend['guid'] = $single->guid;
            $friend['username'] = $single->username;
            $friend['name'] = $single->name;
            $friend['avatar_url'] = get_entity_icon_url($single, 'small');
            $return[] = $friend;
        }
    }
    return $return;
}
示例#2
0
/**
 * Web service to get file list by all users
 *
 * @param string $context eg. all, friends, mine, groups
 * @param int $limit  (optional) default 10
 * @param int $offset (optional) default 0
 * @param int $group_guid (optional)  the guid of a group, $context must be set to 'group'
 * @param string $username (optional) the username of the user default loggedin user
 *
 * @return array $file Array of files uploaded
 */
function file_get_files($context, $limit = 10, $offset = 0, $group_guid, $username)
{
    if (!$username) {
        $user = get_loggedin_user();
    } else {
        $user = get_user_by_username($username);
        if (!$user) {
            throw new InvalidParameterException('registration:usernamenotvalid');
        }
    }
    if ($context == "all") {
        $params = array('types' => 'object', 'subtypes' => 'file', 'limit' => $limit, 'full_view' => FALSE);
    }
    if ($context == "mine" || $context == "user") {
        $params = array('types' => 'object', 'subtypes' => 'file', 'owner_guid' => $user->guid, 'limit' => $limit, 'full_view' => FALSE);
    }
    if ($context == "group") {
        $params = array('types' => 'object', 'subtypes' => 'file', 'container_guid' => $group_guid, 'limit' => $limit, 'full_view' => FALSE);
    }
    $latest_file = elgg_get_entities($params);
    if ($context == "friends") {
        $latest_file = get_user_friends_objects($user->guid, 'file', $limit, $offset);
    }
    if ($latest_file) {
        foreach ($latest_file as $single) {
            $file['guid'] = $single->guid;
            $file['title'] = $single->title;
            $owner = get_entity($single->owner_guid);
            $file['owner']['guid'] = $owner->guid;
            $file['owner']['name'] = $owner->name;
            $file['owner']['avatar_url'] = get_entity_icon_url($owner, 'small');
            $file['container_guid'] = $single->container_guid;
            $file['access_id'] = $single->access_id;
            $file['time_created'] = (int) $single->time_created;
            $file['time_updated'] = (int) $single->time_updated;
            $file['last_action'] = (int) $single->last_action;
            $file['MIMEType'] = $single->mimetype;
            $file['file_icon'] = get_entity_icon_url($single, 'small');
            $return[] = $file;
        }
    } else {
        $msg = elgg_echo('file:none');
        throw new InvalidParameterException($msg);
    }
    return $return;
}
示例#3
0
/**
 * Web service for read latest wire post of user
 *
 * @param string $context all/mine/friends
 * @param string $username username of author
 *
 * @return bool
 */
function wire_get_posts($context, $limit = 10, $offset = 0, $username)
{
    if (!$username) {
        $user = get_loggedin_user();
    } else {
        $user = get_user_by_username($username);
        if (!$user) {
            throw new InvalidParameterException('registration:usernamenotvalid');
        }
    }
    if ($context == "all") {
        $params = array('types' => 'object', 'subtypes' => 'thewire', 'limit' => $limit, 'full_view' => FALSE);
    }
    if ($context == "mine" || $context == "user") {
        $params = array('types' => 'object', 'subtypes' => 'thewire', 'owner_guid' => $user->guid, 'limit' => $limit, 'full_view' => FALSE);
    }
    $latest_wire = elgg_get_entities($params);
    if ($context == "friends") {
        $latest_wire = get_user_friends_objects($user->guid, 'thewire', $limit, $offset);
    }
    if ($latest_wire) {
        foreach ($latest_wire as $single) {
            $wire['guid'] = $single->guid;
            $owner = get_entity($single->owner_guid);
            $wire['owner']['guid'] = $owner->guid;
            $wire['owner']['name'] = $owner->name;
            $wire['owner']['avatar_url'] = get_entity_icon_url($owner, 'small');
            $wire['time_created'] = (int) $single->time_created;
            $wire['description'] = $single->description;
            $return[] = $wire;
        }
    } else {
        $msg = elgg_echo('thewire:noposts');
        throw new InvalidParameterException($msg);
    }
    return $return;
}
示例#4
0
/**
 * Web service get replies on a post
 *
 * @param string $postid GUID of the group
 * @param string $limit   (optional) default 10
 * @param string $offset  (optional) default 0
 *
 * @return bool
 */
function group_forum_get_replies($guid, $limit = 10, $offset = 0)
{
    $topic = get_entity($guid);
    $options = array('guid' => $guid, 'annotation_name' => 'group_topic_post', 'limit' => $limit, 'offset' => $offset);
    $content = elgg_get_annotations($options);
    if ($content) {
        foreach ($content as $single) {
            $post['id'] = $single->id;
            $post['value'] = strip_tags($single->value);
            $post['name'] = $single->name;
            $post['enabled'] = $single->enabled;
            $user = get_entity($single->owner_guid);
            $post['owner']['guid'] = $user->guid;
            $post['owner']['name'] = $user->name;
            $post['owner']['username'] = $user->username;
            $post['owner']['avatar_url'] = get_entity_icon_url($user, 'small');
            $post['entity_guid'] = $single->entity_guid;
            $post['access_id'] = $single->access_id;
            $post['time_created'] = (int) $single->time_created;
            $post['name_id'] = $single->name_id;
            $post['value_id'] = $single->value_id;
            $post['value_type'] = $single->value_type;
            $return[] = $post;
        }
    } else {
        $msg = elgg_echo('discussion:reply:noreplies');
        throw new InvalidParameterException($msg);
    }
    return $return;
}
示例#5
0
文件: entities.php 项目: jricher/Elgg
 /**
  * Return a url for the entity's icon, trying multiple alternatives.
  *
  * @param string $size Either 'large','medium','small' or 'tiny'
  * @return string The url or false if no url could be worked out.
  */
 public function getIcon($size = 'medium')
 {
     if (isset($this->icon_override[$size])) {
         return $this->icon_override[$size];
     }
     return get_entity_icon_url($this, $size);
 }
示例#6
0
    echo "{\"g\":{$guid},\"pog\":{$page_owner_guid},\"c\":[\"mytrips\",\"trip_profile\",\"gallery\"],\"m\":\"{$mac}\",\"i\":[]}";
    /*json_encode([
    		"g" => $guid,
    		"pog" => $page_owner_guid,
    		"c" => $contexts,
    		"m" => $mac,
    		"i" => $input,
    		]);*/
    ?>
></ul>-->
		<a href="<?php 
    echo $user->getURL();
    ?>
" class="">
		<img src="<?php 
    echo get_entity_icon_url($user, 'little');
    ?>
" alt="<?php 
    echo $user->name;
    ?>
" title="<?php 
    echo $user->name;
    ?>
" class=""></a>
	</div>
</li>
<?php 
}
?>
</ul>
示例#7
0
/**
 * Web service to retrieve comments on a blog post
 *
 * @param string $guid blog guid
 * @param string $limit    Number of users to return
 * @param string $offset   Indexing offset, if any
 *
 * @return array
 */
function blog_get_comments($guid, $limit = 10, $offset = 0)
{
    $blog = get_entity($guid);
    $options = array('annotations_name' => 'generic_comment', 'guid' => $guid, 'limit' => $limit, 'pagination' => false, 'reverse_order_by' => true);
    $comments = elgg_get_annotations($options);
    if ($comments) {
        foreach ($comments as $single) {
            $comment['guid'] = $single->id;
            $comment['description'] = strip_tags($single->value);
            $owner = get_entity($single->owner_guid);
            $comment['owner']['guid'] = $owner->guid;
            $comment['owner']['name'] = $owner->name;
            $comment['owner']['username'] = $owner->username;
            $comment['owner']['avatar_url'] = get_entity_icon_url($owner, 'small');
            $comment['time_created'] = (int) $single->time_created;
            $return[] = $comment;
        }
    } else {
        $msg = elgg_echo('generic_comment:none');
        throw new InvalidParameterException($msg);
    }
    return $return;
}
<?php

/**
 * @package Elgg
 * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
 * @author Tingxi Tan, Grid Research Centre [txtan@cpsc.ucalgary.ca]
 * @link http://grc.ucalgary.ca/
 */
require_once dirname(dirname(dirname(__FILE__))) . "/engine/start.php";
//an example to generate JSON with geolocation information
//input from vazco_gmap plugin
$users = get_entities('user', '', 0, '', 9999);
foreach ($users as $user) {
    if ($user->location) {
        //check if location is set
        if (!is_array($user->location)) {
            if (preg_match('/\\((.*),(.*)\\)/', $user->location, $match)) {
                //check if location is input in (lat,lng) format
                $icon = get_entity_icon_url($user, 'medium');
                $url = $user->getURL();
                //this is what will shown in the info bubble
                $info_html = "<div style='height:100px'><p><b>{$user->name}</b></p><a target='_blank' href='{$url}'/><img style='width:50px' src='{$icon}'/></a></div>";
                $batch[] = array('name' => $user->name, 'lat' => $match[1], 'lng' => $match[2], 'info' => $info_html, 'icon' => $icon);
            }
        }
    }
}
$obj['content'] = $batch;
echo json_encode($obj);
示例#9
0
}
$item = $vars['item'];
$annotation = $vars['item']->getAnnotation();
$object = get_entity($item->object_guid);
$subject = get_entity($item->subject_guid);
if (elgg_view_exists($item->view, 'default')) {
    $item->string = elgg_view('river/elements/summary', array('item' => $item), FALSE, FALSE, 'default');
}
if ($object->type == "user" || $object->type == "group") {
    $item->object_metadata['name'] = $object->name;
    $item->object_metadata['username'] = $object->username;
    $item->object_metadata['avatar_url'] = get_entity_icon_url($object, 'medium');
    if ($annotation) {
        $item->object_metadata['message'] = $annotation->value;
    }
    $item->object_metadata['description'] = $object->description;
} else {
    $item->object_metadata['name'] = $object->title;
    if ($annotation) {
        $item->object_metadata['message'] = $annotation->value;
    }
    $item->object_metadata['description'] = $object->description;
}
if ($subject->type == "user" || $object->type == "group") {
    $item->subject_metadata['name'] = $subject->name;
    $item->subject_metadata['username'] = $subject->username;
    $item->subject_metadata['avatar_url'] = get_entity_icon_url($subject, 'small');
} else {
    $item->subject_metadata['name'] = $subject->title;
}
$jsonexport['activity'][] = $vars['item'];
示例#10
0
/**
 * Performs a search of the elgg site
 *
 * @return array $results search result
 */
function site_search($query, $offset, $limit, $sort, $order, $search_type, $entity_type, $entity_subtype, $owner_guid, $container_guid)
{
    $params = array('query' => $query, 'offset' => $offset, 'limit' => $limit, 'sort' => $sort, 'order' => $order, 'search_type' => $search_type, 'type' => $entity_type, 'subtype' => $entity_subtype, 'owner_guid' => $owner_guid, 'container_guid' => $container_guid);
    $types = get_registered_entity_types();
    foreach ($types as $type => $subtypes) {
        $results = elgg_trigger_plugin_hook('search', $type, $params, array());
        if ($results === FALSE) {
            // someone is saying not to display these types in searches.
            continue;
        }
        if ($results['count']) {
            foreach ($results['entities'] as $single) {
                //search matched critera
                /*
                $result['search_matched_title'] = $single->getVolatileData('search_matched_title');
                $result['search_matched_description'] = $single->getVolatileData('search_matched_description');
                $result['search_matched_extra'] = $single->getVolatileData('search_matched_extra');
                */
                if ($type == 'group' || $type == 'user') {
                    $result['title'] = $single->name;
                } else {
                    $result['title'] = $single->title;
                }
                $result['guid'] = $single->guid;
                $result['type'] = $single->type;
                $result['subtype'] = get_subtype_from_id($single->subtype);
                $result['avatar_url'] = get_entity_icon_url($single, 'small');
                $return[$type] = $result;
            }
        }
    }
    return $return;
}
示例#11
0
/**
 * Web service to get sent messages
 *
 * @param string $limit  (optional) default 10
 * @param string $offset (optional) default 0
 *
 * @return array $mesage Array of files uploaded
 */
function messages_sent($limit = 10, $offset = 0)
{
    $user = get_loggedin_user();
    $params = array('type' => 'object', 'subtype' => 'messages', 'metadata_name' => 'fromId', 'metadata_value' => $user->guid, 'owner_guid' => $user->guid, 'full_view' => false);
    $list = elgg_get_entities_from_metadata($params);
    if ($list) {
        foreach ($list as $single) {
            $message['guid'] = $single->guid;
            $message['subject'] = $single->title;
            $user = get_entity($single->toId);
            $message['user']['guid'] = $user->guid;
            $message['user']['name'] = $user->name;
            $message['user']['username'] = $user->username;
            $message['user']['avatar_url'] = get_entity_icon_url($user, 'small');
            $message['timestamp'] = (int) $single->time_created;
            $message['description'] = $single->description;
            if ($single->readYet) {
                $message['read'] = "yes";
            } else {
                $message['read'] = "no";
            }
            $return[] = $message;
        }
    } else {
        $msg = elgg_echo('messages:nomessages');
        throw new InvalidParameterException($msg);
    }
    return $return;
}