Exemplo n.º 1
0
function pleiofile_add_folder_to_zip(ZipArchive &$zip_archive, ElggObject $folder, $folder_path = "")
{
    if (!empty($zip_archive) && !empty($folder) && elgg_instanceof($folder, "object", "folder")) {
        $folder_title = elgg_get_friendly_title($folder->title);
        $zip_archive->addEmptyDir($folder_path . $folder_title);
        $folder_path .= $folder_title . DIRECTORY_SEPARATOR;
        $file_options = array("type" => "object", "subtype" => "file", "limit" => false, "relationship" => "folder_of", "relationship_guid" => $folder->getGUID());
        // add files from this folder to the zip
        if ($files = elgg_get_entities_from_relationship($file_options)) {
            foreach ($files as $file) {
                // check if the file exists
                if ($zip_archive->statName($folder_path . $file->originalfilename) === false) {
                    // doesn't exist, so add
                    $zip_archive->addFile($file->getFilenameOnFilestore(), $folder_path . sanitize_file_name($file->originalfilename));
                } else {
                    // file name exists, so create a new one
                    $ext_pos = strrpos($file->originalfilename, ".");
                    $file_name = substr($file->originalfilename, 0, $ext_pos) . "_" . $file->getGUID() . substr($file->originalfilename, $ext_pos);
                    $zip_archive->addFile($file->getFilenameOnFilestore(), $folder_path . sanitize_file_name($file_name));
                }
            }
        }
        // check if there are subfolders
        $folder_options = array("type" => "object", "subtype" => "folder", "limit" => false, "metadata_name_value_pairs" => array("parent_guid" => $folder->getGUID()));
        if ($sub_folders = elgg_get_entities_from_metadata($folder_options)) {
            foreach ($sub_folders as $sub_folder) {
                pleiofile_add_folder_to_zip($zip_archive, $sub_folder, $folder_path);
            }
        }
    }
}
Exemplo n.º 2
0
/**
 * Get the sites this object is part of
 *
 * @param int $object_guid The object's GUID
 * @param int $limit       Number of results to return
 * @param int $offset      Any indexing offset
 *
 * @return array On success, an array of ElggSites
 */
function get_object_sites($object_guid, $limit = 10, $offset = 0)
{
    $object_guid = (int) $object_guid;
    $limit = (int) $limit;
    $offset = (int) $offset;
    return elgg_get_entities_from_relationship(array('relationship' => 'member_of_site', 'relationship_guid' => $object_guid, 'types' => 'site', 'limit' => $limit, 'offset' => $offset));
}
Exemplo n.º 3
0
 /**
  * @SWG\Get(
  *     path="/api/groups/{guid}/members",
  *     security={{"oauth2": {"all"}}},
  *     tags={"members"},
  *     summary="Find members in a specific group.",
  *     description="Find the members from a specific group.",
  *     produces={"application/json"},
  *     @SWG\Parameter(
  *         name="guid",
  *         in="path",
  *         description="The guid of the specific group",
  *         required=true,
  *         type="integer",
  *         @SWG\Items(type="integer")
  *     ),
  *     @SWG\Parameter(
  *         name="offset",
  *         in="query",
  *         description="Offset the results by",
  *         default=0,
  *         required=false,
  *         type="integer",
  *         @SWG\Items(type="integer")
  *     ),
  *     @SWG\Parameter(
  *         name="limit",
  *         in="query",
  *         description="Limit the results by",
  *         default=20,
  *         required=false,
  *         type="integer",
  *         @SWG\Items(type="integer")
  *     ),
  *     @SWG\Response(
  *         response=200,
  *         description="Succesful operation.",
  *         @SWG\Schema(
  *             type="array",
  *             @SWG\Items(ref="#/definitions/Event")
  *         ),
  *     ),
  *     @SWG\Response(
  *         response="404",
  *         description="Could not find the requested event.",
  *     )
  * )
  */
 public function getGroup($request, $response, $args)
 {
     $currentUser = elgg_get_logged_in_user_entity();
     $guid = (int) $args['guid'];
     $group = get_entity($guid);
     if (!$group | !$group instanceof \ElggGroup) {
         return $response->withStatus(404);
     }
     $params = $request->getQueryParams();
     $limit = (int) $params['limit'];
     $offset = (int) $params['offset'];
     if (!$limit | $limit < 0 | $limit > 100) {
         $limit = 20;
     }
     $db_prefix = elgg_get_config('dbprefix');
     $options = array('relationship' => 'member', 'relationship_guid' => $group->guid, 'inverse_relationship' => true, 'type' => 'user', 'limit' => $limit, 'offset' => $offset, 'joins' => array("JOIN {$db_prefix}users_entity oe ON e.guid = oe.guid"), 'order_by' => 'oe.name');
     $entities = array();
     foreach (elgg_get_entities_from_relationship($options) as $entity) {
         $entities[] = $this->parseUser($entity);
     }
     $options['count'] = true;
     $total = elgg_get_entities_from_relationship($options);
     $response = $response->withHeader('Content-type', 'application/json');
     return $response->write(json_encode(array('total' => $total, 'entities' => $entities), JSON_PRETTY_PRINT));
 }
Exemplo n.º 4
0
 /**
  * Counts the number of registrations
  *
  * @return boolean|int
  */
 public function countRegistrations()
 {
     $old_ia = elgg_set_ignore_access(true);
     $result = elgg_get_entities_from_relationship(array("relationship" => EVENT_MANAGER_RELATION_SLOT_REGISTRATION, "relationship_guid" => $this->getGUID(), "inverse_relationship" => true, "count" => true, "site_guids" => false));
     elgg_set_ignore_access($old_ia);
     return $result;
 }
Exemplo n.º 5
0
 public function countAttendees($count = true)
 {
     $old_ia = elgg_set_ignore_access(true);
     $entities = elgg_get_entities_from_relationship(array('relationship' => ZHAOHU_MANAGER_RELATION_ATTENDING, 'relationship_guid' => $this->getGUID(), 'inverse_relationship' => FALSE, 'count' => $count));
     elgg_set_ignore_access($old_ia);
     return $entities;
 }
Exemplo n.º 6
0
function threads_get_all_replies($entity_guid, $options = array())
{
    $options['relationship_guid'] = $entity_guid;
    $defaults = array('relationship' => 'top', 'inverse_relationship' => true, 'order_by' => 'e.time_created asc');
    $options = array_merge($defaults, $options);
    return elgg_get_entities_from_relationship($options);
}
 public function GetPendingNotifications($data)
 {
     $notifications = elgg_get_entities_from_relationship(array('relationship' => \WizmassNotifier\Interfaces\WizmassNotification::HAS_ACTOR, 'relationship_guid' => $data->token->user_guid, 'inverse_relationship' => true));
     $readNotifications = elgg_get_entities_from_relationship(array('relationship' => \WizmassNotifier\Interfaces\WizmassNotification::WAS_READ, 'relationship_guid' => $data->token->user_guid, 'inverse_relationship' => true));
     $readNotificationsGuids = array_map(function ($item) {
         return $item->guid;
     }, $readNotifications);
     $this->logger->info('processing ' . count($notifications) . ' notifications');
     $notificationFactory = NotificationFactory::getInstance();
     /** @var WizmassNotification[] $notificationsToSend */
     $notificationsToSend = [];
     /** @var \ElggEntity $notification */
     foreach ($notifications as $notification) {
         /** @var WizmassNotification $wizmassNotification */
         $wizmassNotification = $notificationFactory->Build($notification);
         if (!$wizmassNotification) {
             $this->logger->info('error building notification: ' . $notification->guid);
         } else {
             $data = $wizmassNotification->BuildNotificationData();
             if (!in_array($notification->guid, $readNotificationsGuids)) {
                 $data['read'] = false;
             } else {
                 $data['read'] = true;
             }
             $notificationsToSend[] = $data;
         }
     }
     return $notificationsToSend;
 }
Exemplo n.º 8
0
function friend_request_pagesetup()
{
    $context = elgg_get_context();
    $page_owner = elgg_get_page_owner_entity();
    // Remove link to friendsof
    elgg_unregister_menu_item("page", "friends:of");
    if ($user = elgg_get_logged_in_user_entity()) {
        $options = array("type" => "user", "count" => true, "relationship" => "friendrequest", "relationship_guid" => $user->getGUID(), "inverse_relationship" => true);
        if ($count = elgg_get_entities_from_relationship($options)) {
            $params = array("name" => "friend_request", "href" => "friend_request/" . $user->username, "text" => elgg_view_icon("user") . "<span class='friend-request-new'>" . $count . "</span>", "title" => elgg_echo("friend_request:menu"), "priority" => 301);
            elgg_register_menu_item("topbar", $params);
        }
    }
    // Show menu link in the correct context
    if (in_array($context, array("friends", "friendsof", "collections", "messages")) && !empty($page_owner) && $page_owner->canEdit()) {
        $options = array("type" => "user", "count" => true, "relationship" => "friendrequest", "relationship_guid" => $page_owner->getGUID(), "inverse_relationship" => true);
        if ($count = elgg_get_entities_from_relationship($options)) {
            $extra = " [" . $count . "]";
        } else {
            $extra = "";
        }
        // add menu item
        $menu_item = array("name" => "friend_request", "text" => elgg_echo("friend_request:menu") . $extra, "href" => "friend_request/" . $page_owner->username, "contexts" => array("friends", "friendsof", "collections", "messages"), "section" => "friend_request");
        elgg_register_menu_item("page", $menu_item);
    }
}
Exemplo n.º 9
0
 /**
  * Counts the number of registrations
  *
  * @return boolean|int
  */
 public function countRegistrations()
 {
     $old_ia = elgg_set_ignore_access(true);
     $result = elgg_get_entities_from_relationship(['relationship' => EVENT_MANAGER_RELATION_SLOT_REGISTRATION, 'relationship_guid' => $this->getGUID(), 'inverse_relationship' => true, 'count' => true, 'site_guids' => false]);
     elgg_set_ignore_access($old_ia);
     return $result;
 }
Exemplo n.º 10
0
function file_tools_object_handler_delete($event, $type, $object)
{
    static $delete_files;
    if (!empty($object) && elgg_instanceof($object, "object", FILE_TOOLS_SUBTYPE)) {
        // find subfolders
        $options = array("type" => "object", "subtype" => FILE_TOOLS_SUBTYPE, "container_guid" => $object->getContainerGUID(), "limit" => false, "metadata_name_value_pairs" => array("name" => "parent_guid", "value" => $object->getGUID()), "wheres" => array("(e.guid <> " . $object->getGUID() . ")"));
        if ($subfolders = elgg_get_entities_from_metadata($options)) {
            // delete subfolders
            foreach ($subfolders as $subfolder) {
                $subfolder->delete();
            }
        }
        // fill the static, to delete files in a folder
        if (!isset($delete_files)) {
            $delete_files = false;
            if (get_input("files") == "yes") {
                $delete_files = true;
            }
        }
        // should we remove files?
        if ($delete_files) {
            // find file in this folder
            $options = array("type" => "object", "subtype" => "file", "container_guid" => $object->getContainerGUID(), "limit" => false, "relationship" => FILE_TOOLS_RELATIONSHIP, "relationship_guid" => $object->getGUID());
            if ($files = elgg_get_entities_from_relationship($options)) {
                // delete files in folder
                foreach ($files as $file) {
                    $file->delete();
                }
            }
        }
    }
}
Exemplo n.º 11
0
function gvfriendrequest_pagesetup()
{
    $context = elgg_get_context();
    $page_owner = elgg_get_page_owner_entity();
    // Remove link to friendsof
    elgg_unregister_menu_item("page", "friends:of");
    if ($user = elgg_get_logged_in_user_entity()) {
        $options = array("type" => "user", "count" => true, "relationship" => "friendrequest", "relationship_guid" => $user->getGUID(), "inverse_relationship" => true);
        if ($count = elgg_get_entities_from_relationship($options)) {
            $class = "elgg-icon elgg-icon-users";
            $text = "<span class='{$class}'></span>";
            $tooltip = elgg_echo('gvtheme:myfriends');
            if ($count > 0) {
                $text .= "<span class=\"messages-new\">{$count}</span>";
                $tooltip = elgg_echo("friend_request:unreadcount", array($count));
            }
            $params = array("name" => "friends", "href" => "friend_request/" . $user->username, "text" => $text, "section" => 'alt', "title" => $tooltip);
            elgg_register_menu_item("topbar", $params);
        }
    }
    // Show menu link in the correct context
    if (in_array($context, array("friends", "friendsof", "collections")) && !empty($page_owner) && $page_owner->canEdit()) {
        $options = array("type" => "user", "count" => true, "relationship" => "friendrequest", "relationship_guid" => $page_owner->getGUID(), "inverse_relationship" => true);
        if ($count = elgg_get_entities_from_relationship($options)) {
            $extra = " (" . $count . ")";
        } else {
            $extra = "";
        }
        // add menu item
        $menu_item = array("name" => "friend_request", "text" => elgg_echo("friend_request:menu") . $extra, "href" => "friend_request/" . $page_owner->username, "contexts" => array("friends", "friendsof", "collections"), "section" => "friend_request");
        elgg_register_menu_item("page", $menu_item);
    }
}
Exemplo n.º 12
0
/**
 * Get latest posts
 *
 * @param int $container_guid	Guid of the topic or forum
 * @param int $limit			Number of posts to return
 * @param boolean $count		Return a total number of posts
 * @param boolean $recursive	Recurse into the forum tree (nested forums and topics)
 * @return mixed
 */
function hj_forum_get_latest_posts($container_guid, $limit = 10, $count = false, $recursive = false)
{
    $options = array('types' => 'object', 'subtypes' => array('hjforumpost', 'hjforumtopic'), 'count' => $count, 'limit' => $limit, 'relationship' => 'descendant', 'relationship_guid' => $container_guid, 'inverse_relationship' => true, 'order_by' => 'e.time_created DESC');
    if (!$recursive) {
        $options['container_guids'] = $container_guid;
    }
    return elgg_get_entities_from_relationship($options);
}
Exemplo n.º 13
0
/**
 * Get a list of entities sorted by priority
 *
 * @param string $type
 * @param string $subtype
 * @param int $owner_guid
 * @param int $container_guid
 * @param int $limit
 * @return array An array of ElggEntity
 */
function hj_framework_get_entities_by_priority($options = array())
{
    if (!is_array($options) || empty($options)) {
        return false;
    }
    $defaults = array('order_by_metadata' => array('name' => 'priority', 'value' => 'ASC'));
    $options = array_merge($defaults, $options);
    return elgg_get_entities_from_relationship($options);
}
Exemplo n.º 14
0
/**
 * Gives the list of the group related groups
 *
 * @param ElggGroup $group
 * @return array
 */
function get_relatedgroups($group, $options = array())
{
    if ($group instanceof ElggGroup) {
        $options['relationship'] = 'related';
        $options['relationship_guid'] = $group->guid;
        return elgg_get_entities_from_relationship(array($options));
    } else {
        return false;
    }
}
Exemplo n.º 15
0
function get_parent_group($guid)
{
    global $CONFIG;
    $parent = elgg_get_entities_from_relationship(array('types' => array('group'), 'limit' => 1, 'relationship' => AU_SUBGROUPS_RELATIONSHIP, 'relationship_guid' => $guid));
    if (is_array($parent)) {
        $CONFIG->padre = $parent[0];
        //echo $CONFIG->padre->guid;
        return $parent[0];
    }
}
Exemplo n.º 16
0
function pleio_rest_subsite_plugin_enabled(Subsite $site)
{
    $db_prefix = elgg_get_config('dbprefix');
    $options = array('type' => 'object', 'subtype' => 'plugin', 'relationship_guid' => $site->guid, 'relationship' => 'active_plugin', 'inverse_relationship' => true, 'site_guid' => $site->guid, 'joins' => array("JOIN {$db_prefix}objects_entity oe on oe.guid = e.guid"), 'selects' => array("oe.title"), 'wheres' => array("oe.title = \"pleio_rest\""));
    $plugin_enabled = elgg_get_entities_from_relationship($options);
    if (count($plugin_enabled) == 1) {
        return true;
    }
    return false;
}
Exemplo n.º 17
0
 /**
  * Get all calendars this event is on
  * 
  * @param array custom parameters to override the default egef
  * @param bool $public - limit to only personal public calendars?
  */
 public function getCalendars($params = array(), $public = false)
 {
     $defaults = array('type' => 'object', 'subtype' => 'calendar', 'relationship' => Calendar::EVENT_CALENDAR_RELATIONSHIP, 'relationship_guid' => $this->guid, 'limit' => false);
     $options = array_merge($defaults, $params);
     if ($public) {
         $options['metadata_name_value_pairs'][] = array('name' => '__public_calendar', 'value' => true);
     }
     if ($options['count']) {
         return elgg_get_entities_from_relationship($options);
     }
     return new ElggBatch('elgg_get_entities_from_relationship', $options);
 }
Exemplo n.º 18
0
 public function getSites()
 {
     $db_prefix = get_config('dbprefix');
     $sites = array();
     foreach (subsite_manager_get_user_subsites($user->guid) as $site) {
         $plugin_enabled = elgg_get_entities_from_relationship(array('type' => 'object', 'subtype' => 'plugin', 'relationship_guid' => $site->guid, 'relationship' => 'active_plugin', 'inverse_relationship' => true, 'site_guid' => $site->guid, 'joins' => array("JOIN {$db_prefix}objects_entity oe on oe.guid = e.guid"), 'selects' => array("oe.title", "oe.description"), 'wheres' => array("oe.title = 'pleiobox'"), 'limit' => 1));
         if (count($plugin_enabled) === 1) {
             $sites[] = array('name' => $site->name, 'url' => $site->url);
         }
     }
     return $this->sendResponse($sites);
 }
Exemplo n.º 19
0
function subgroups_inherit_members($event, $type, $object)
{
    $parent_guid = get_input('au_subgroups_parent_guid', false);
    if ($parent_guid) {
        if ($_POST['subgroups_inherit_members_enable'] == "yes") {
            //get parent group members
            $oldMembers = elgg_get_entities_from_relationship(array("relationship" => "member", "relationship_guid" => $parent_guid, "inverse_relationship" => true, 'limit' => 200));
            foreach ($oldMembers as $oldMember) {
                $object->join($oldMember);
            }
        }
    }
}
Exemplo n.º 20
0
/**
 * Get categories an entity is filed in
 *
 * @param int $entity_guid GUID of an entity
 * @param array $params Additional parameters to be passed to the getter function
 * @param bool $as_guids Return an array of GUIDs
 * @return array Array of filed items
 */
function get_entity_categories($entity_guid, $params = array(), $as_guids = false)
{
    $defaults = array('types' => 'object', 'subtypes' => HYPECATEGORIES_SUBTYPE, 'reltionship' => HYPECATEGORIES_RELATIONSHIP, 'inverse_relationship' => false, 'limit' => false);
    $params = array_merge($defaults, $params);
    $params['relationship_guid'] = $entity_guid;
    $categories = elgg_get_entities_from_relationship($params);
    if ($as_guids && $categories) {
        foreach ($categories as $key => $category) {
            $categories[$key] = $category->guid;
        }
    }
    return $categories;
}
Exemplo n.º 21
0
/**
 * Checks if the user has a specific role
 *
 * @param ElggUser $user
 * @return bool True if the user belongs to the passed role, false otherwise
 */
function roles_has_role($user = null, $role_name = DEFAULT_ROLE)
{
    $user = $user ? $user : elgg_get_logged_in_user_entity();
    if (!elgg_instanceof($user, 'user')) {
        return false;
    }
    $options = array('type' => 'object', 'subtype' => 'role', 'metadata_name_value_pairs' => array('name' => 'name', 'value' => $role_name, 'operand' => '='), 'relationship' => 'has_role', 'relationship_guid' => $user->guid);
    $roles = elgg_get_entities_from_relationship($options);
    if (is_array($roles) && !empty($roles)) {
        return true;
    }
    return false;
}
Exemplo n.º 22
0
/**
 * Send push notifications if event is added to the activity river
 * 
 * @param string        $event      name of the event
 * @param string        $type       type of the event
 * @param ElggRiverItem $river_item river item object
 * 
 * @return void
 */
function ws_pack_created_river_event_handler($event, $type, $river_item)
{
    if (!empty($river_item) && $river_item instanceof ElggRiverItem) {
        if (!function_exists('str_get_html')) {
            elgg_load_library("simple_html_dom");
        }
        $message = "";
        $html_view = elgg_view_river_item($river_item);
        if ($res = str_get_html($html_view)) {
            // get the river summary
            if ($summary_element = $res->find("div.elgg-river-summary")) {
                $summary_element = $summary_element[0];
                $text = $summary_element->innertext();
                list($left, $right) = explode("<span class=\"elgg-river-timestamp\">", $text);
                $message = trim(elgg_strip_tags($left));
            }
        }
        if (!empty($message)) {
            $user_guids = false;
            switch ($river_item->access_id) {
                case ACCESS_PRIVATE:
                    // do nothing
                    break;
                case ACCESS_PUBLIC:
                case ACCESS_LOGGED_IN:
                    // notify everyone
                    $site_user_options = array("type" => "user", "limit" => false, "relationship" => "member_of_site", "relationship_guid" => elgg_get_site_entity()->getGUID(), "inverse_relationship" => true, "callback" => "ws_pack_row_to_guid");
                    $user_guids = elgg_get_entities_from_relationship($site_user_options);
                    break;
                case ACCESS_FRIENDS:
                    // notify friends of subject_guid
                    $friends_options = array("type" => "user", "limit" => false, "relationship" => "friend", "relationship_guid" => $river_item->subject_guid, "callback" => "ws_pack_row_to_guid", "joins" => array("JOIN " . elgg_get_config("dbprefix") . "entity_relationships r2 ON e.guid = r2.guid_one"), "wheres" => array("(r2.relationship = 'member_of_site' AND r2.guid_two = " . elgg_get_site_entity()->getGUID() . ")"));
                    $user_guids = elgg_get_entities_from_relationship($friends_options);
                    break;
                default:
                    // probably some acl, so notify members of the acl
                    $user_guids = get_members_of_access_collection($river_item->access_id, true);
                    break;
            }
            // we found potential interested users, so push
            if (!empty($user_guids) && is_array($user_guids)) {
                $api_application_options = array("type" => "object", "subtype" => APIApplication::SUBTYPE, "limit" => false, "annotation_name" => "push_notification_service");
                if ($api_applications = elgg_get_entities_from_annotations($api_application_options)) {
                    foreach ($api_applications as $api_application) {
                        $api_application->sendPushNotification($message, $user_guids);
                    }
                }
            }
        }
    }
}
Exemplo n.º 23
0
 /**
  * Add menu items to the topbar
  *
  * @param string          $hook         the name of the hook
  * @param string          $type         the type of the hook
  * @param \ElggMenuItem[] $return_value the current return value
  * @param array           $params       supplied params
  *
  * @return void|\ElggMenuItem[]
  */
 public static function register($hook, $type, $return_value, $params)
 {
     $user = elgg_get_logged_in_user_entity();
     if (empty($user)) {
         return;
     }
     $options = ['type' => 'user', 'count' => true, 'relationship' => 'friendrequest', 'relationship_guid' => $user->getGUID(), 'inverse_relationship' => true];
     $count = elgg_get_entities_from_relationship($options);
     if (empty($count)) {
         return;
     }
     $return_value[] = \ElggMenuItem::factory(['name' => 'friend_request', 'href' => "friend_request/{$user->username}", 'text' => elgg_view_icon('user') . elgg_format_element('span', ['class' => 'friend-request-new'], $count), 'title' => elgg_echo('friend_request:menu'), 'priority' => 301]);
     return $return_value;
 }
Exemplo n.º 24
0
/**
 * Returns river data
 * 
 * @param string $filter            filter name
 * @param array  $guids             guids of groups
 * @param int    $offset            offset
 * @param int    $limit             limit
 * @param int    $posted_time_lower lower time stamp to limit results
 * 
 * @return array|ErrorResult
 */
function ws_pack_river_get($filter, $guids = array(), $offset = 0, $limit = 25, $posted_time_lower = 0)
{
    $result = false;
    $dbprefix = elgg_get_config("dbprefix");
    // default options
    $options = array("offset" => $offset, "limit" => $limit, "posted_time_lower" => $posted_time_lower, "joins" => array("JOIN " . $dbprefix . "entities sue ON rv.subject_guid = sue.guid", "JOIN " . $dbprefix . "entities obe ON rv.object_guid = obe.guid"), "wheres" => array("(sue.enabled = 'yes' AND obe.enabled = 'yes')"));
    // what to return
    switch ($filter) {
        case "mine":
            $options["subject_guid"] = elgg_get_logged_in_user_guid();
            break;
        case "friends":
            $options["relationship_guid"] = elgg_get_logged_in_user_guid();
            $options["relationship"] = "friend";
            break;
        case "groups":
            if (empty($guids)) {
                // get group guids
                $group_options = array("type" => "group", "relationship" => "member", "relationship_guid" => elgg_get_logged_in_user_guid(), "limit" => false, "callback" => "ws_pack_row_to_guid");
                $guids = elgg_get_entities_from_relationship($group_options);
            }
            // check if there are groups
            if (!empty($guids)) {
                $options["joins"] = array("JOIN " . $dbprefix . "entities e ON rv.object_guid = e.guid");
                $options["wheres"] = array("(rv.object_guid IN (" . implode(",", $guids) . ") OR e.container_guid IN (" . implode(",", $guids) . "))");
            } else {
                // no groups found, so make sure not to return anything
                $options = false;
            }
            break;
        case "all":
        default:
            // list everything
            break;
    }
    // get river items
    if ($options && ($items = elgg_get_river($options))) {
        $result = ws_pack_export_river_items($items);
    }
    // did we get river items
    if ($result === false) {
        $result = new ErrorResult(elgg_echo("river:none"), WS_PACK_API_NO_RESULTS);
    }
    return $result;
}
Exemplo n.º 25
0
 public function getFolderContents($path = array())
 {
     $db_prefix = elgg_get_config("dbprefix");
     $options = array('type' => 'object', 'subtype' => 'file', 'container_guid' => $this->container->guid, 'limit' => false, 'joins' => "JOIN {$db_prefix}objects_entity oe ON e.guid = oe.guid", 'order_by' => 'oe.title ASC');
     if (count($path) === 0) {
         $parent_guid = 0;
         $options['wheres'] = "NOT EXISTS (\n                    SELECT 1 FROM {$db_prefix}entity_relationships r\n                    WHERE r.guid_two = e.guid AND\n                    r.relationship = '" . FILE_TOOLS_RELATIONSHIP . "')";
         $files = elgg_get_entities($options);
     } else {
         $parent_guid = array_slice($path, -1)[0];
         $options['relationship'] = FILE_TOOLS_RELATIONSHIP;
         $options['relationship_guid'] = $parent_guid;
         $files = elgg_get_entities_from_relationship($options);
     }
     $options = array('type' => 'object', 'subtype' => 'folder', 'container_guid' => $this->container->guid, 'limit' => false, 'metadata_name_value_pairs' => array(array('name' => 'parent_guid', 'value' => $parent_guid)), 'joins' => "JOIN {$db_prefix}objects_entity oe ON e.guid = oe.guid", 'order_by' => 'oe.title ASC');
     $folders = elgg_get_entities_from_metadata($options);
     return array_merge($folders, $files);
 }
 /**
  * {@inheritdoc}
  */
 public function handle(\ElggEntity $entity)
 {
     $shortname = $this->getShortname();
     $current_relationships = elgg_get_entities_from_relationship(array('relationship_guid' => (int) $entity->guid, 'relationship' => $shortname, 'inverse_relationship' => $this->inverse_relationship, 'limit' => 0, 'callback' => false));
     $current_relationships_ids = array();
     if (is_array($current_relationships) && count($current_relationships)) {
         foreach ($current_relationships as $rel) {
             $current_relationships_ids[] = $rel->guid;
         }
     }
     $future_relationships_ids = get_input($this->getShortname(), array());
     if (!is_array($future_relationships_ids)) {
         $future_relationships_ids = array();
     }
     $params = array('field' => $this, 'entity' => $entity, 'relationship' => $shortname, 'value' => $current_relationships_ids, 'future_value' => $future_relationships_ids);
     // Allow plugins to prevent relationship from being changed
     if (!elgg_trigger_plugin_hook('handle:relationship:before', 'prototyper', $params, true)) {
         return $entity;
     }
     $to_delete = array_diff($current_relationships_ids, $future_relationships_ids);
     foreach ($to_delete as $guid) {
         if (!$this->inverse_relationship || $this->bilateral) {
             remove_entity_relationship($entity->guid, $shortname, $guid);
         }
         if ($this->inverse_relationship || $this->bilateral) {
             remove_entity_relationship($guid, $shortname, $entity->guid);
         }
     }
     foreach ($future_relationships_ids as $guid) {
         if (!$this->inverse_relationship || $this->bilateral) {
             if (!check_entity_relationship($entity->guid, $shortname, $guid)) {
                 add_entity_relationship($entity->guid, $shortname, $guid);
             }
         }
         if ($this->inverse_relationship || $this->bilateral) {
             if (!check_entity_relationship($guid, $shortname, $entity->guid)) {
                 add_entity_relationship($guid, $shortname, $entity->guid);
             }
         }
     }
     $params = array('field' => $this, 'entity' => $entity, 'relationship_name' => $shortname, 'value' => $future_relationships_ids, 'previous_value' => $current_relationships_ids);
     elgg_trigger_plugin_hook('handle:relationship:after', 'prototyper', $params, true);
     return $entity;
 }
Exemplo n.º 27
0
 /**
  * Add menu items to the page menu
  *
  * @param string          $hook         the name of the hook
  * @param string          $type         the type of the hook
  * @param \ElggMenuItem[] $return_value the current return value
  * @param array           $params       supplied params
  *
  * @return void|\ElggMenuItem[]
  */
 public static function register($hook, $type, $return_value, $params)
 {
     $page_owner = elgg_get_page_owner_entity();
     if (!$page_owner instanceof \ElggUser) {
         return;
     }
     if (!$page_owner->canEdit()) {
         return;
     }
     // count pending requests
     $options = ['type' => 'user', 'count' => true, 'relationship' => 'friendrequest', 'relationship_guid' => $page_owner->getGUID(), 'inverse_relationship' => true];
     $count = elgg_get_entities_from_relationship($options);
     $extra = '';
     if (!empty($count)) {
         $extra = ' [' . $count . ']';
     }
     // add menu item
     $return_value[] = \ElggMenuItem::factory(['name' => 'friend_request', 'text' => elgg_echo('friend_request:menu') . $extra, 'href' => "friend_request/{$page_owner->username}", 'contexts' => ['friends', 'friendsof', 'collections', 'messages']]);
     return $return_value;
 }
Exemplo n.º 28
0
 /**
  * @SWG\Get(
  *     path="/api/groups/mine",
  *     security={{"oauth2": {"all"}}},
  *     tags={"groups"},
  *     summary="Retrieve a list of groups the current user is member of.",
  *     description="Retrieve a list of groups the current user is member of.",
  *     produces={"application/json"},
  *     @SWG\Parameter(
  *         name="offset",
  *         in="query",
  *         description="Offset the results by",
  *         default=0,
  *         required=false,
  *         type="integer",
  *         @SWG\Items(type="integer")
  *     ),
  *     @SWG\Parameter(
  *         name="limit",
  *         in="query",
  *         description="Limit the results by",
  *         default=20,
  *         required=false,
  *         type="integer",
  *         @SWG\Items(type="integer")
  *     ),
  *     @SWG\Response(
  *         response=200,
  *         description="Succesful operation.",
  *         @SWG\Schema(
  *             type="array",
  *             @SWG\Items(ref="#/definitions/Group")
  *         ),
  *     )
  * )
  */
 public function getMine($request, $response, $args)
 {
     $params = $request->getQueryParams();
     $limit = (int) $params['limit'];
     $offset = (int) $params['offset'];
     if (!$limit | $limit < 0 | $limit > 100) {
         $limit = 20;
     }
     $current_user = elgg_get_logged_in_user_entity();
     $dbprefix = elgg_get_config("dbprefix");
     $options = array('type' => 'group', 'limit' => $limit, 'offset' => $offset, 'joins' => array("JOIN {$dbprefix}groups_entity ge ON e.guid = ge.guid"), 'order_by' => 'ge.name', 'relationship' => 'member', 'relationship_guid' => $current_user->guid);
     $entities = array();
     foreach (elgg_get_entities_from_relationship($options) as $entity) {
         $entities[] = $this->parseGroup($entity);
     }
     $options['count'] = true;
     $total = elgg_get_entities($options);
     $response = $response->withHeader('Content-type', 'application/json');
     return $response->write(json_encode(array('total' => $total, 'entities' => $entities), JSON_PRETTY_PRINT));
 }
Exemplo n.º 29
0
/**
 * Listen to the upgrade event
 *
 * @param string $event  name of the event
 * @param string $type   type of the event
 * @param null   $object supplied object
 *
 * @return void
 */
function content_subscriptions_upgrade_system_handler($event, $type, $object)
{
    // Upgrade also possible hidden entities. This feature get run
    // by an administrator so there's no need to ignore access.
    $access_status = access_get_show_hidden_status();
    access_show_hidden_entities(true);
    // register an upgrade script
    $options = array("type" => "user", "relationship" => CONTENT_SUBSCRIPTIONS_SUBSCRIPTION, "inverse_relationship" => true, "count" => true);
    $count = elgg_get_entities_from_relationship($options);
    if ($count) {
        $path = "admin/upgrades/content_subscriptions";
        $upgrade = new ElggUpgrade();
        if (!$upgrade->getUpgradeFromPath($path)) {
            $upgrade->setPath($path);
            $upgrade->title = "Content Subscription upgrade";
            $upgrade->description = "The way content subscriptions are handled has changed. Run this script to make sure all content subscriptions are migrated.";
            $upgrade->save();
        }
    }
    access_show_hidden_entities($access_status);
}
Exemplo n.º 30
0
 /**
  * Delete image
  *
  * @return bool
  */
 public function delete()
 {
     // check if batch should be deleted
     $batch = elgg_get_entities_from_relationship(array('relationship' => 'belongs_to_batch', 'relationship_guid' => $this->guid, 'inverse_relationship' => false));
     if ($batch) {
         $batch = $batch[0];
         $count = elgg_get_entities_from_relationship(array('relationship' => 'belongs_to_batch', 'relationship_guid' => $batch->guid, 'inverse_relationship' => true, 'count' => true));
         if ($count == 1) {
             // last image so delete batch
             $batch->delete();
         }
     }
     $album = get_entity($this->container_guid);
     if ($album) {
         $album->removeImage($this->guid);
     }
     $this->removeThumbnails();
     // update quota
     $owner = $this->getOwnerEntity();
     $owner->image_repo_size = (int) $owner->image_repo_size - $this->size();
     return parent::delete();
 }