Example #1
0
 /**
  * {@inheritdoc}
  */
 public function put(ParameterBag $params)
 {
     $user = get_entity($params->guid);
     $site = elgg_get_site_entity();
     if ($this->delete($params)) {
         $token = hypeGraph()->tokens->create($user, $site, TokenService::LONG_EXPIRES);
     }
     if (empty($token)) {
         throw new GraphException("Unable to generate a new user token", 500);
     }
     return array('token' => $token->token, 'expires' => date(DATE_ATOM, $token->expires), 'user' => $user, 'site_uid' => "se{$token->site_guid}");
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function put(ParameterBag $params)
 {
     $action = new SavePost();
     $action->post = get_entity($params->guid);
     $action->poster = $action->post ? $action->post->getOwnerEntity() : elgg_get_logged_in_user_entity();
     $action->container = $action->post ? $action->post->getContainerEntity() : $action->poster;
     $action->subtype = Post::SUBTYPE;
     if ($action->post) {
         foreach (array('status', 'address', 'location', 'access_id', 'tags') as $key) {
             if ($params->{$key} === null) {
                 $params->{$key} = $action->post->{$key};
             }
         }
     }
     $action->status = $params->status;
     $action->address = $params->address;
     $action->location = $params->location;
     $action->tags = $params->tags;
     $action->friend_guids = array();
     $action->upload_guids = array();
     $action->attachment_guids = array();
     $action->make_bookmark = $params->make_bookmark && !$action->post;
     $action->access_id = isset($params->access_id) ? $params->access_id : get_default_access($action->poster);
     $friend_uids = (array) $params->friend_uids;
     foreach ($friend_uids as $uid) {
         $action->friend_guids[] = $this->graph->get($uid)->guid;
     }
     $attachment_uids = (array) $params->attachment_uids;
     foreach ($attachment_uids as $uid) {
         $action->attachment_guids[] = $this->graph->get($uid)->guid;
     }
     $upload_uids = (array) $params->upload_uids;
     foreach ($upload_uids as $uid) {
         $upload = $this->graph->get($uid);
         if ($upload && $upload->origin == 'graph' && $upload->access_id == ACCESS_PRIVATE) {
             $action->upload_guids[] = $upload->guid;
         } else {
             hypeGraph()->logger->log("Can not use node {$uid} as upload. Only resources uploaded via Graph API with private access can be attached.", "ERROR");
         }
     }
     try {
         if ($action->validate() !== false) {
             $action->execute();
         }
         if (!$action->post) {
             throw new \Exception(implode(', ', $action->getResult()->getErrors()));
         }
     } catch (\Exception $ex) {
         throw new GraphException($ex->getMessage());
     }
     return ['nodes' => [$action->post, $action->river, $action->bookmark]];
 }
 /**
  * {@inheritdoc}
  */
 public function post(ParameterBag $params)
 {
     $reply_to = get_entity($params->guid);
     $from = elgg_get_logged_in_user_entity();
     $subject = strip_tags($params->subject);
     $message = $params->message;
     if (elgg_is_active_plugin('hypeInbox')) {
         if (!$reply_to instanceof InboxMessage) {
             throw new GraphException('Can not instantiate the message');
         }
         $action = new SendMessage();
         $action->entity = $reply_to;
         $action->subject = $params->subject;
         $action->body = $params->message;
         $action->attachment_guids = array();
         $action->sender_guid = $from->guid;
         $action->recipient_guids = $reply_to->getParticipantGuids();
         $attachment_uids = (array) $params->attachment_uids;
         foreach ($attachment_uids as $uid) {
             $attachment = $this->graph->get($uid);
             if ($attachment && $attachment->origin == 'graph' && $attachment->access_id == ACCESS_PRIVATE) {
                 $action->attachment_guids[] = $attachment->guid;
             } else {
                 hypeGraph()->logger->log("Can not use node {$uid} as attachment. Only resources uploaded via Graph API with private access can be attached.", "ERROR");
             }
         }
         try {
             if ($action->validate() !== false) {
                 $action->execute();
             }
             $message = $action->entity;
             if (!$message) {
                 throw new Exception(implode(', ', $action->getResult()->getErrors()));
             }
         } catch (Exception $ex) {
             throw new GraphException($ex->getMessage());
         }
         return array('nodes' => array($message));
     } else {
         $id = messages_send($subject, $message, $reply_to->fromId, $from->guid, $reply_to->guid);
         return array('nodes' => array(get_entity($id)));
     }
 }
Example #4
0
 /**
  * Export batch
  * @return stdClass
  */
 public function export()
 {
     $result = new stdClass();
     $this->options['count'] = true;
     $result->total = (int) call_user_func($this->getter, $this->options);
     unset($this->options['count']);
     $result->limit = elgg_extract('limit', $this->options, elgg_get_config('default_limit'));
     $result->offset = elgg_extract('offset', $this->options, 0);
     $batch = new ElggBatch($this->getter, $this->options);
     $result->nodes = array();
     $i = $result->offset;
     foreach ($batch as $entity) {
         if (is_callable(array($entity, 'toObject'))) {
             $result->nodes["{$i}"] = $entity->toObject();
         } else {
             $result->nodes["{$i}"] = $entity;
         }
         $i++;
     }
     hypeGraph()->logger->log(array('BatchOptions' => $this->options));
     return $result;
 }
Example #5
0
 /**
  * Returns page handler ID
  * @return string
  */
 public function getPageHandlerId()
 {
     return hypeGraph()->config->get('pagehandler_id');
 }
Example #6
0
<?php

$routes = hypeGraph()->graph->exportRoutes();
$allowed_endpoints = (array) elgg_extract('endpoints', $vars, $entity->endpoints);
?>
<table class="elgg-table-alt ws-endpoints-form" style="width:100%">
	<thead>
		<tr>
			<th><?php 
echo elgg_echo('graph:endpoint');
?>
</th>
			<th><?php 
echo elgg_echo('graph:description');
?>
</th>
		</tr>
	</thead>
	<tbody>
		<?php 
foreach ($routes as $route) {
    $endpoint = $route['endpoint'];
    ?>
			<tr>
				<td>
					<strong>
						<?php 
    echo $endpoint;
    ?>
					</strong>
				</td>
Example #7
0
 /**
  * Deletes api keys
  * @return bool
  */
 public function deleteApiKeys()
 {
     return hypeGraph()->api_keys->revoke($this->getPublicKey());
 }
Example #8
0
 /**
  * Returns all configured routes
  * @return array
  */
 public function exportRoutes()
 {
     $output = array();
     $request_types = array(HttpRequest::METHOD_GET, HttpRequest::METHOD_POST, HttpRequest::METHOD_PUT, HttpRequest::METHOD_DELETE);
     $routes = hypeGraph()->router->getRoutes();
     foreach ($routes as $route => $ctrl) {
         try {
             if (!class_exists($ctrl) || !in_array(ControllerInterface::class, class_implements($ctrl))) {
                 continue;
             }
             $ctrl = new $ctrl();
             foreach ($request_types as $request_type) {
                 $method_parameters = $ctrl->params($request_type);
                 if (!is_array($method_parameters) || !is_callable(array($ctrl, strtolower($request_type)))) {
                     continue;
                 }
                 $visible_parameters = array_filter($method_parameters, function ($pe) {
                     return !$pe instanceof HiddenParameter;
                 });
                 $parameters = array_map(function ($pe) {
                     if ($pe instanceof Parameter) {
                         return $pe->toArray();
                     }
                 }, $visible_parameters);
                 $request = "{$request_type} /{$route}";
                 $output[] = array_filter(array('method' => $route, 'call_method' => $request_type, 'endpoint' => $request, 'description' => elgg_echo($request), 'parameters' => !empty($parameters) ? $parameters : null));
             }
         } catch (Exception $ex) {
             // do nothing
         }
     }
     return $output;
 }
Example #9
0
 /**
  * {@inheritdoc}
  */
 public function put(ParameterBag $params)
 {
     hypeGraph()->logger->vardump('params', $params);
     $user = isset($params->owner_guid) && $params->owner_guid ? get_entity($params->owner_guid) : elgg_get_logged_in_user_entity();
     $group_guid = isset($params->guid) ? $params->guid : 0;
     // allows us to recycle this method from SiteGroups controller
     $is_new_group = $group_guid == 0;
     if ($is_new_group && elgg_get_plugin_setting('limited_groups', 'groups') == 'yes' && !$user->isAdmin()) {
         throw new GraphException(elgg_echo("groups:cantcreate"), 403);
     }
     $group = $group_guid ? get_entity($group_guid) : new ElggGroup();
     if (elgg_instanceof($group, "group") && !$group->canEdit()) {
         throw new GraphException(elgg_echo("groups:cantedit"), 403);
     }
     if (!$is_new_group) {
         foreach ($params as $key => $value) {
             if ($value === null) {
                 $params->{$key} = $group->{$key};
             }
         }
     }
     $input = array();
     foreach (elgg_get_config('group') as $shortname => $valuetype) {
         $input[$shortname] = $params->{$shortname};
         if (is_array($input[$shortname])) {
             array_walk_recursive($input[$shortname], function (&$v) {
                 $v = _elgg_html_decode($v);
             });
         } else {
             $input[$shortname] = _elgg_html_decode($input[$shortname]);
         }
         if ($valuetype == 'tags') {
             $input[$shortname] = string_to_tag_array($input[$shortname]);
         }
     }
     $input = array_filter($input);
     $input['name'] = htmlspecialchars(get_input('name', '', false), ENT_QUOTES, 'UTF-8');
     // Assume we can edit or this is a new group
     if (sizeof($input) > 0) {
         foreach ($input as $shortname => $value) {
             // update access collection name if group name changes
             if (!$is_new_group && $shortname == 'name' && $value != $group->name) {
                 $group_name = html_entity_decode($value, ENT_QUOTES, 'UTF-8');
                 $ac_name = sanitize_string(elgg_echo('groups:group') . ": " . $group_name);
                 $acl = get_access_collection($group->group_acl);
                 if ($acl) {
                     // @todo Elgg api does not support updating access collection name
                     $db_prefix = elgg_get_config('dbprefix');
                     $query = "UPDATE {$db_prefix}access_collections SET name = '{$ac_name}'\n\t\t\t\t\tWHERE id = {$group->group_acl}";
                     update_data($query);
                 }
             }
             if ($value === '') {
                 // The group profile displays all profile fields that have a value.
                 // We don't want to display fields with empty string value, so we
                 // remove the metadata completely.
                 $group->deleteMetadata($shortname);
                 continue;
             }
             $group->{$shortname} = $value;
         }
     }
     // Validate create
     if (!$group->name) {
         throw new GraphException(elgg_echo("groups:notitle"), 400);
     }
     // Set group tool options
     $tool_options = elgg_get_config('group_tool_options');
     if ($tool_options) {
         foreach ($tool_options as $group_option) {
             $option_toggle_name = $group_option->name . "_enable";
             $option_default = $group->{$option_toggle_name} ?: $group_option->default_on ? 'yes' : 'no';
             $group->{$option_toggle_name} = $params->{$option_toggle_name} ?: $option_default;
         }
     }
     // Group membership - should these be treated with same constants as access permissions?
     $is_public_membership = (int) $params->membership == ACCESS_PUBLIC;
     $group->membership = $is_public_membership ? ACCESS_PUBLIC : ACCESS_PRIVATE;
     $group->setContentAccessMode($params->content_access_mode);
     if ($is_new_group) {
         $group->owner_guid = $user->guid;
         $group->access_id = ACCESS_PUBLIC;
     }
     if ($is_new_group) {
         // if new group, we need to save so group acl gets set in event handler
         if (!$group->save()) {
             throw new GraphException(elgg_echo("groups:save_error"));
         }
     }
     if (elgg_get_plugin_setting('hidden_groups', 'groups') == 'yes') {
         $visibility = (int) $params->vis;
         if ($visibility == ACCESS_PRIVATE) {
             // Make this group visible only to group members. We need to use
             // ACCESS_PRIVATE on the form and convert it to group_acl here
             // because new groups do not have acl until they have been saved once.
             $visibility = $group->group_acl;
             // Force all new group content to be available only to members
             $group->setContentAccessMode(ElggGroup::CONTENT_ACCESS_MODE_MEMBERS_ONLY);
         }
         $group->access_id = $visibility;
     }
     if (!$group->save()) {
         throw new GraphException(elgg_echo("groups:save_error"));
     }
     $river_id = false;
     if ($is_new_group) {
         elgg_set_page_owner_guid($group->guid);
         $group->join($user);
         $river_id = elgg_create_river_item(array('view' => 'river/group/create', 'action_type' => 'create', 'subject_guid' => $user->guid, 'object_guid' => $group->guid));
     }
     $return = array('nodes' => array('group' => $group));
     if ($river_id) {
         $river = elgg_get_river(array('ids' => $river_id));
         $return['nodes']['activity'] = $river ? $river[0] : $river_id;
     }
     return $return;
 }
Example #10
0
<?php

/**
 * RESTful Graph
 *
 * @package hypeJunction
 * @subpackage hypeGraph
 *
 * @author Ismayil Khayredinov <*****@*****.**>
 */
require_once __DIR__ . '/autoloader.php';
hypeGraph()->boot();
Example #11
0
 /**
  * Prepare API request result
  * @return stdClass Object containing the result
  */
 public function export()
 {
     $result = new stdClass();
     $result->result = $this->getResult();
     $result->status = $this->getStatusCode();
     $result->message = $this->getStatusMessage();
     if (get_input('debug') || hypeGraph()->config->get('debug_mode')) {
         $result->log = hypeGraph()->logger->log();
         $result->viewtype = elgg_get_viewtype();
     }
     if (hypeGraph()->config->get('debug_mode')) {
         $result->debug = new stdClass();
         $result->debug->input = array_merge((array) $_REQUEST, (array) elgg_get_config('input'));
         $result->debug->postdata = file_get_contents('php://input');
         $result->debug->vardump = hypeGraph()->logger->vardump();
         $result->debug->session = new stdClass();
         $consumer = hypeGraph()->session->consumer();
         $user = hypeGraph()->session->user();
         $result->debug->session->logged_in_user = $user ? $user->toObject() : null;
         $result->debug->session->consumer = $consumer ? $consumer->toObject() : null;
         $result->debug->exception_trace = $this->exception instanceof Exception ? $this->exception->getTrace()[0] : null;
     }
     return $result;
 }