function jssor_entity_menu_setup($hook, $type, $return, $params) { if (elgg_in_context('widgets')) { return $return; } $entity = $params['entity']; $handler = elgg_extract('handler', $params, false); if ($handler != 'photos') { return $return; } if (elgg_instanceof($entity, 'object', 'image')) { $album = $entity->getContainerEntity(); $url = 'jssor/album?guid=' . $album->getGUID() . '&i=' . $entity->getGUID(); $params = array('href' => $url, 'text' => elgg_echo('jssor:gallery:view')); $text = elgg_view('output/url', $params); $options = array('name' => 'gallery_view', 'text' => $text, 'priority' => 40); $return[] = ElggMenuItem::factory($options); } if (elgg_instanceof($entity, 'object', 'album')) { $album = $entity; $offset = get_input('offset'); if ($offset) { $url = 'jssor/album?guid=' . $album->getGUID() . '&o=' . get_input('offset'); } else { $url = 'jssor/album?guid=' . $album->getGUID(); } $params = array('href' => $url, 'text' => elgg_echo('jssor:gallery:view')); $text = elgg_view('output/url', $params); $options = array('name' => 'gallery_view', 'text' => $text, 'priority' => 40); $return[] = ElggMenuItem::factory($options); } return $return; }
/** * Set folder breadcrumb menu * * @param string $hook the name of the hook * @param string $type the type of the hook * @param ElggMenuItem[] $return_value current return value * @param array $params supplied params * * @return void|ElggMenuItem[] */ public static function register($hook, $type, $return_value, $params) { if (empty($params) || !is_array($params)) { return; } $container = elgg_get_page_owner_entity(); /* @var $folder \ElggObject */ $folder = elgg_extract('entity', $params); if (elgg_instanceof($folder, 'object', FILE_TOOLS_SUBTYPE)) { $container = $folder->getContainerEntity(); $priority = 9999999; $return_value[] = \ElggMenuItem::factory(['name' => "folder_{$folder->getGUID()}", 'text' => $folder->getDisplayName(), 'href' => false, 'priority' => $priority]); $parent_guid = (int) $folder->parent_guid; while (!empty($parent_guid)) { $parent = get_entity($parent_guid); if (!elgg_instanceof($parent, 'object', FILE_TOOLS_SUBTYPE)) { break; } $priority--; $return_value[] = \ElggMenuItem::factory(['name' => "folder_{$parent->getGUID()}", 'text' => $parent->getDisplayName(), 'href' => $parent->getURL(), 'priority' => $priority]); $parent_guid = (int) $parent->parent_guid; } } // make main folder item $main_folder_options = ['name' => 'main_folder', 'text' => elgg_echo('file_tools:list:folder:main'), 'priority' => 0]; if ($container instanceof \ElggGroup) { $main_folder_options['href'] = "file/group/{$container->getGUID()}/all#"; } else { $main_folder_options['href'] = "file/owner/{$container->username}/all#"; } $return_value[] = \ElggMenuItem::factory($main_folder_options); return $return_value; }
function au_group_tag_menu_page_handler($page, $identifier) { //show the page of search results // assumes url of group/guid/tag // if the tag is 'all' then will display a tagcloud switch ($page[0]) { case 'group': $entity = get_entity($page[1]); if (!elgg_instanceof($entity, 'group') || $entity->au_group_tag_menu_enable == 'no') { return false; } elgg_push_breadcrumb($entity->name, $entity->getURL()); //should be OK if this is empty $tag = $page[2]; elgg_push_breadcrumb($tag); if ($tag == "all") { //show a tag cloud for all group tags //arbitrarily set to a max of 640 tags - should be enough for anyone :-) $title = elgg_echo("au_group_tag_menu:tagcloud"); $options = array('container_guid' => $entity->getGUID(), 'type' => 'object', 'threshold' => 0, 'limit' => 640, 'tag_names' => array('tags')); $thetags = elgg_get_tags($options); //make it an alphabetical tag cloud, not with most popular first sort($thetags); //find the highest tag count for scaling the font $max = 0; foreach ($thetags as $key) { if ($key->total > $max) { $max = $key->total; } } $content = " "; //loop through and generate tags so they display nicely //in the group, not as a dumb search page foreach ($thetags as $key) { $url = elgg_get_site_url() . "group_tag_menu/group/" . $entity->getGUID() . "/" . urlencode($key->tag); $taglink = elgg_view('output/url', array('text' => ' ' . $key->tag, 'href' => $url, 'title' => "{$key->tag} ({$key->total})", 'rel' => 'tag')); // get the font size for the tag (taken from elgg's own tagcloud code - not sure I love this) $size = round(log($key->total) / log($max + 0.0001) * 100) + 30; if ($size < 100) { $size = 100; } // generate the link $content .= " <a href='{$url}' style='font-size:{$size}%'>" . $key->tag . "</a> "; } } else { //show the results for the selected tag $title = elgg_echo("au_group_tag_menu:title") . "{$tag}"; $options = array('type' => 'object', 'metadata_name' => 'tags', 'metadata_value' => $tag, 'container_guid' => $entity->guid, 'full_view' => false); $content = elgg_list_entities_from_metadata($options); } //display the page if (!$content) { $content = elgg_echo('au_group_tag_menu:noresults'); } $layout = elgg_view_layout('content', array('title' => elgg_view_title($title), 'content' => $content, 'filter' => false)); echo elgg_view_page($title, $layout); break; } return true; }
/** * Setups entity interactions menu * * @param string $hook "register" * @param string $type "menu:interactions" * @param array $menu Menu * @param array $params Hook parameters * @uses $params['entity'] An entity that we are interacting with * @uses $params['active_tab'] Currently active tab, default to 'comments' * @return array */ public static function interactionsMenuSetup($hook, $type, $menu, $params) { $entity = elgg_extract('entity', $params, false); /* @var ElggEntity $entity */ if (!elgg_instanceof($entity)) { return $menu; } $active_tab = elgg_extract('active_tab', $params); // Commenting $comments_count = $entity->countComments(); $can_comment = $entity->canComment(); if ($can_comment) { $menu[] = ElggMenuItem::factory(array('name' => 'comments', 'text' => $entity instanceof Comment ? elgg_echo('interactions:reply:create') : elgg_echo('interactions:comment:create'), 'href' => "stream/comments/{$entity->guid}", 'priority' => 200, 'data-trait' => 'comments', 'item_class' => 'interactions-action')); } if ($can_comment || $comments_count) { $menu[] = ElggMenuItem::factory(array('name' => 'comments:badge', 'text' => elgg_view('framework/interactions/elements/badge', array('entity' => $entity, 'icon' => 'comments', 'type' => 'comments', 'count' => $comments_count)), 'href' => "stream/comments/{$entity->guid}", 'selected' => $active_tab == 'comments', 'priority' => 100, 'data-trait' => 'comments', 'item_class' => 'interactions-tab')); } if (elgg_is_active_plugin('likes')) { // Liking and unliking $likes_count = $entity->countAnnotations('likes'); $can_like = $entity->canAnnotate(0, 'likes'); $does_like = elgg_annotation_exists($entity->guid, 'likes'); if ($can_like) { $before_text = elgg_echo('interactions:likes:before'); $after_text = elgg_echo('interactions:likes:after'); $menu[] = ElggMenuItem::factory(array('name' => 'likes', 'text' => $does_like ? $after_text : $before_text, 'href' => "action/stream/like?guid={$entity->guid}", 'is_action' => true, 'priority' => 400, 'link_class' => 'interactions-state-toggler', 'item_class' => 'interactions-action', 'data-guid' => $entity->guid, 'data-trait' => 'likes', 'data-state' => $does_like ? 'after' : 'before')); } if ($can_like || $likes_count) { $menu[] = ElggMenuItem::factory(array('name' => 'likes:badge', 'text' => elgg_view('framework/interactions/elements/badge', array('entity' => $entity, 'icon' => 'likes', 'type' => 'likes', 'count' => $likes_count)), 'href' => "stream/likes/{$entity->guid}", 'selected' => $active_tab == 'likes', 'data-trait' => 'likes', 'priority' => 300, 'item_class' => 'interactions-tab')); } } return $menu; }
/** * When a blog is removed also remove it's icons * * @param string $event 'delete' * @param string $type 'object' * @param ElggObject $object The ElggObject being removed * * @return void */ public static function cleanupBlogIcon($event, $type, $object) { if (!elgg_instanceof($object, "object", "blog", "ElggBlog")) { return; } blog_tools_remove_blog_icon($object); }
/** * Produce the navigation tree * * @param ElggEntity $container Container entity for the pages * * @return array */ function pages_get_navigation_tree($container) { if (!elgg_instanceof($container)) { return; } $top_pages = new ElggBatch('elgg_get_entities', array('type' => 'object', 'subtype' => 'page_top', 'container_guid' => $container->getGUID(), 'limit' => false)); /* @var ElggBatch $top_pages Batch of top level pages */ $tree = array(); $depths = array(); foreach ($top_pages as $page) { $tree[] = array('guid' => $page->getGUID(), 'title' => $page->title, 'url' => $page->getURL(), 'depth' => 0); $depths[$page->guid] = 0; $stack = array(); array_push($stack, $page); while (count($stack) > 0) { $parent = array_pop($stack); $children = new ElggBatch('elgg_get_entities_from_metadata', array('type' => 'object', 'subtype' => 'page', 'metadata_name' => 'parent_guid', 'metadata_value' => $parent->getGUID(), 'limit' => false)); foreach ($children as $child) { $tree[] = array('guid' => $child->getGUID(), 'title' => $child->title, 'url' => $child->getURL(), 'parent_guid' => $parent->getGUID(), 'depth' => $depths[$parent->guid] + 1); $depths[$child->guid] = $depths[$parent->guid] + 1; array_push($stack, $child); } } } return $tree; }
/** * https://github.com/Elgg/Elgg/pull/6393 * Hook handlers for 'access:collections:write','all' hook should respect * group's content access mode and container write permissions */ public function testWriteAccessArray() { $membersonly = ElggGroup::CONTENT_ACCESS_MODE_MEMBERS_ONLY; $unrestricted = ElggGroup::CONTENT_ACCESS_MODE_UNRESTRICTED; $original_page_owner = elgg_get_page_owner_entity(); elgg_set_page_owner_guid($this->group->guid); $ia = elgg_set_ignore_access(false); // User is not a member of the group // Member-only group $this->group->setContentAccessMode($membersonly); $write_access = get_write_access_array($this->user->guid, true); $this->assertFalse(array_key_exists($this->group->group_acl, $write_access)); // Unrestricted group $this->group->setContentAccessMode($unrestricted); $write_access = get_write_access_array($this->user->guid, true); $this->assertFalse(array_key_exists($this->group->group_acl, $write_access)); // User is a member (can write to container) $this->group->join($this->user); // Member-only group $this->group->setContentAccessMode($membersonly); $write_access = get_write_access_array($this->user->guid, true); $this->assertTrue(array_key_exists($this->group->group_acl, $write_access)); // Unrestricted group $this->group->setContentAccessMode($unrestricted); $write_access = get_write_access_array($this->user->guid, true); $this->assertTrue(array_key_exists($this->group->group_acl, $write_access)); elgg_set_ignore_access($ia); $this->group->leave($this->user); $original_page_owner_guid = elgg_instanceof($original_page_owner) ? $original_page_owner->guid : 0; elgg_set_page_owner_guid($original_page_owner_guid); }
/** * Take over the groupicon page handler for fallback * * @param array $page the url elements * * @return void */ function group_tools_groupicon_page_handler($page) { // group guid if (!isset($page[0])) { header("HTTP/1.1 400 Bad Request"); exit; } $group_guid = $page[0]; $group = get_entity($group_guid); if (empty($group) || !elgg_instanceof($group, "group")) { header("HTTP/1.1 400 Bad Request"); exit; } $owner_guid = $group->getOwnerGUID(); $icontime = (int) $group->icontime; if (empty($icontime)) { header("HTTP/1.1 404 Not Found"); exit; } // size $size = "medium"; if (isset($page[1])) { $icon_sizes = elgg_get_config("icon_sizes"); if (!empty($icon_sizes) && array_key_exists($page[1], $icon_sizes)) { $size = $page[1]; } } $params = array("group_guid" => $group_guid, "guid" => $owner_guid, "size" => $size, "icontime" => $icontime); $url = elgg_http_add_url_query_elements("mod/group_tools/pages/groups/thumbnail.php", $params); forward($url); }
/** * Take some actions during the login event of a user * * @param string $event 'login' is the event this function handles * @param string $type 'user' is the type for this event * @param ElggUser $object the current user trying to login * * @return void */ function simplesaml_login_event_handler($event, $type, $object) { if (empty($object) || !elgg_instanceof($object, "user")) { return; } if (!isset($_SESSION["saml_attributes"]) || !isset($_SESSION["saml_source"])) { return; } $saml_attributes = $_SESSION["saml_attributes"]; $source = $_SESSION["saml_source"]; if (!simplesaml_is_enabled_source($source)) { return; } if (!simplesaml_validate_authentication_attributes($source, $saml_attributes)) { return; } $saml_uid = elgg_extract("elgg:external_id", $saml_attributes); if (!empty($saml_uid)) { if (is_array($saml_uid)) { $saml_uid = $saml_uid[0]; } // save the external id so the next login will go faster simplesaml_link_user($object, $source, $saml_uid); } // save the attributes to the user simplesaml_save_authentication_attributes($object, $source, $saml_attributes); // save source name for single logout $_SESSION["saml_login_source"] = $source; unset($_SESSION["saml_attributes"]); unset($_SESSION["saml_source"]); }
/** * Performs action when a widget is created * * @param string $event name of the system event * @param string $object_type type of the event * @param mixed $object object related to the event * * @return void */ function widget_manager_create_object_handler($event, $object_type, $object) { if (elgg_instanceof($object, "object", "widget", "ElggWidget")) { $owner = $object->getOwnerEntity(); // Updates access for privately created widgets in a group or on site if ((int) $object->access_id === ACCESS_PRIVATE) { $old_ia = elgg_set_ignore_access(); if ($owner instanceof ElggGroup) { $object->access_id = $owner->group_acl; $object->save(); } elseif ($owner instanceof ElggSite) { $object->access_id = ACCESS_PUBLIC; $object->save(); } elgg_set_ignore_access($old_ia); } // Adds a relation between a widget and a multidashboard object $dashboard_guid = get_input("multi_dashboard_guid"); if ($dashboard_guid && widget_manager_multi_dashboard_enabled()) { $dashboard = get_entity($dashboard_guid); if (elgg_instanceof($dashboard, "object", MultiDashboard::SUBTYPE, "MultiDashboard")) { add_entity_relationship($object->getGUID(), MultiDashboard::WIDGET_RELATIONSHIP, $dashboard->getGUID()); } } } }
function hj_forum_get_forum_category_input_options($entity = null, $container = null) { if ((elgg_instanceof($container, 'site') || elgg_instanceof($container, 'group')) && !HYPEFORUM_CATEGORIES_TOP) { return false; } if (elgg_instanceof($container, 'object', 'hjforum') && !HYPEFORUM_CATEGORIES) { return false; } if (!$entity && !$container) { return false; } if (elgg_instanceof($container, 'object', 'hjforum') && !$container->enable_subcategories) { return false; } $dbprefix = elgg_get_config('dbprefix'); $categories = elgg_get_entities(array('types' => 'object', 'subtypes' => 'hjforumcategory', 'limit' => 0, 'container_guids' => $container->guid, 'joins' => array("JOIN {$dbprefix}objects_entity oe ON oe.guid = e.guid"), 'order_by' => 'oe.title ASC')); if ($categories) { foreach ($categories as $category) { $options_values[$category->guid] = $category->title; } if ($entity) { $categories = $entity->getCategories('hjforumcategory'); $value = $categories[0]->guid; } $options = array('input_type' => 'dropdown', 'options_values' => $options_values, 'value' => $value); } else { if ($container->canWriteToContainer(0, 'object', 'hjforumcategory')) { $options = array('input_type' => 'text', 'override_view' => 'output/url', 'text' => elgg_echo('hj:forum:create:category'), 'href' => "forum/create/category/{$container->guid}"); } else { return false; } } return $options; }
/** * Add or remove widgets based on the group tool option * * @param string $hook 'group_tool_widgets' * @param string $type 'widget_manager' * @param array $return_value current enable/disable widget handlers * @param array $params supplied params * * @return array */ public static function groupTools($hook, $type, $return_value, $params) { if (empty($params) || is_array($params)) { return $return_value; } $entity = elgg_extract("entity", $params); if (empty($entity) || !elgg_instanceof($entity, "group")) { return $return_value; } if (!is_array($return_value)) { $return_value = array(); } if (!isset($return_value["enable"])) { $return_value["enable"] = array(); } if (!isset($return_value["disable"])) { $return_value["disable"] = array(); } // check different group tools for which we supply widgets if ($entity->blog_enable == "yes") { $return_value["enable"][] = "blog"; } else { $return_value["disable"][] = "blog"; } return $return_value; }
/** * Delete entity event * * @param string $event "delete" * @param string $type "object"|"group"|"user" * @param ElggEntity $entity Entity * @return void */ function elgg_solr_delete_entity($event, $type, $entity) { if (!elgg_instanceof($entity)) { return; } if (!elgg_solr_is_registered_entity_type($entity->type, $entity->getSubtype())) { return; } // if shutdown just do it, otherwise defer if ($GLOBALS['shutdown_flag']) { $client = elgg_solr_get_client(); $query = $client->createUpdate(); $query->addDeleteById($entity->guid); $query->addCommit(); try { $client->update($query); } catch (Exception $ex) { //something went wrong, lets cache the id and try again on cron elgg_get_site_entity()->annotate('elgg_solr_delete_cache', $entity->guid, ACCESS_PUBLIC); elgg_solr_debug_log($ex->getMessage()); } } else { elgg_solr_defer_index_delete($entity->guid); } }
function au_landing_page_update($event, $type, $object) { if (!elgg_instanceof($object, 'page') && elgg_instanceof($object, 'page_top')) { return true; } // only process this event once if (elgg_get_config('page_update_notify_sent_' . $object->guid)) { return true; } elgg_set_config('page_update_notify_sent_' . $object->guid, true); // get revision history for the page $revisions = $object->getAnnotations(array('annotation_name' => 'page', 'limit' => false)); // create an array of unique users to notify, excluding the current user // and the object owner (as core notifies them) $users = array(); foreach ($revisions as $revision) { if ($revision->owner_guid != $object->owner_guid && $revision->owner_guid != elgg_get_logged_in_user_guid()) { $users[] = $revision->owner_guid; } } $users = array_unique($users); // notify the users if (count($users)) { notify_user($users, elgg_get_logged_in_user_guid(), elgg_echo('au_landing:page:update:subject', array($object->title)), elgg_echo('au_landing:page:update:message', array($object->title, elgg_get_logged_in_user_entity()->name, $object->getURL()))); } }
function au_landing_subgroups_access($group, $user, $limit, $returnvalue = array(), $depth = 0) { if (!elgg_instanceof($group, 'group')) { return $returnvalue; } if (!elgg_instanceof($user, 'user')) { return $returnvalue; } $depth++; $children = \AU\SubGroups\get_subgroups($group, 0, true); if (is_array($children) && count($children)) { foreach ($children as $child) { if ($child->isMember($user)) { // it's a valid subgroup that we're a member of, add it to the access list $label = ''; for ($i = 0; $i < min($depth, $limit); $i++) { $label .= '--'; } $label .= $child->name; unset($returnvalue[$child->group_acl]); //necessary because it may already be set in the wrong tree $returnvalue[$child->group_acl] = $label; $returnvalue = au_landing_subgroups_access($child, $user, $limit, $returnvalue, $depth); } } } return $returnvalue; }
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(); } } } } }
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); } } } }
function friend_request_entity_menu_handler($hook, $type, $returnvalue, $params) { $result = $returnvalue; if (!empty($params) && is_array($params) && ($user = elgg_get_logged_in_user_entity())) { $entity = elgg_extract("entity", $params); if (elgg_instanceof($entity, "user") && $entity->getGUID() != $user->getGUID()) { if (!empty($result) && !is_array($result)) { $result = array($result); } elseif (empty($result)) { $result = array(); } // are we friends if (!$entity->isFriendOf($user->getGUID())) { // no, check if pending request if (check_entity_relationship($user->getGUID(), "friendrequest", $entity->getGUID())) { // pending request $result[] = ElggMenuItem::factory(array("name" => "friend_request", "text" => elgg_echo("friend_request:friend:add:pending"), "href" => "friend_request/" . $user->username . "#friend_request_sent_listing", "priority" => 500)); } else { // add as friend $result[] = ElggMenuItem::factory(array("name" => "add_friend", "text" => elgg_echo("friend:add"), "href" => "action/friends/add?friend=" . $entity->getGUID(), "is_action" => true, "priority" => 500)); } } else { // is friend, se remove friend link $result[] = ElggMenuItem::factory(array("name" => "remove_friend", "text" => elgg_echo("friend:remove"), "href" => "action/friends/remove?friend=" . $entity->getGUID(), "is_action" => true, "priority" => 500)); } } } return $result; }
function questions_notify_message_handler($hook, $entity_type, $returnvalue, $params) { $entity = $params['entity']; $to_entity = $params['to_entity']; $method = $params['method']; if (elgg_instanceof($entity, 'object', 'question')) { $descr = $entity->description; $title = $entity->title; $url = $entity->getURL(); $owner = $entity->getOwnerEntity(); $via = elgg_echo("questions:via"); if ($method == 'sms') { //shortening the url for sms $url = elgg_get_site_url() . "view/{$entity->guid}"; return "{$owner->name} {$via}: {$url} ({$title})"; } if ($method == 'email') { return "{$owner->name} {$via}: {$title} \n\n {$descr} \n\n {$url}"; } if ($method == 'web') { return "{$owner->name} {$via}: {$title} \n\n {$descr} \n\n {$url}"; } } return null; }
/** * This functions performs actions when a wire post is created * * @param string $event 'create' * @param string $type 'object' * @param ElggObject $object the ElggObject created * * @return void */ function thewire_tools_create_object_event_handler($event, $type, ElggObject $object) { if (empty($object) || !elgg_instanceof($object, "object", "thewire")) { return; } //send out notification to users mentioned in a wire post $usernames = array(); preg_match_all("/\\@([A-Za-z0-9\\_\\.\\-]+)/i", $object->description, $usernames); if (empty($usernames)) { return; } $usernames = array_unique($usernames[0]); $params = array("object" => $object, "action" => "mention"); foreach ($usernames as $username) { $username = str_ireplace("@", "", $username); $user = get_user_by_username($username); if (empty($user) || $user->getGUID() == $object->getOwnerGUID()) { continue; } $setting = thewire_tools_get_notification_settings($user->getGUID()); if (empty($setting)) { continue; } $subject = elgg_echo("thewire_tools:notify:mention:subject"); $message = elgg_echo("thewire_tools:notify:mention:message", array($user->name, $object->getOwnerEntity()->name, elgg_normalize_url("thewire/search/@" . $user->username))); notify_user($user->getGUID(), $object->getOwnerGUID(), $subject, $message, $params, $setting); } }
/** * Listen to the login event to make sure the user is validated * * @param string $event the name of the event * @param string $type the type of the event * @param ElggUser $user supplied user * * @return bool */ function uservalidationbyadmin_login_event($event, $type, $user) { $result = false; // make sure we can see all users $hidden = access_get_show_hidden_status(); access_show_hidden_entities(true); // do we actualy have a user if (!empty($user) && elgg_instanceof($user, "user")) { // is the user enabled if ($user->isEnabled()) { if ($user->isAdmin()) { // admins are always allowed $result = true; } elseif (isset($user->admin_validated)) { // check if the user is validated if ($user->admin_validated) { // user is validated and can login $result = true; } } else { // user has register before this plugin was activated $result = true; } } } // check if the user can login if (empty($result)) { // register error register_error(elgg_echo("uservalidationbyadmin:login:error")); } // restore access setting access_show_hidden_entities($hidden); return $result; }
/** * */ public function setUp($hook, $type, $menu, $params) { if (!elgg_is_logged_in()) { return $menu; } $user = elgg_get_logged_in_user_entity(); if (!$user->isAdmin() && $user->role !== 'curator') { return $menu; } $entity = $params['entity']; if (elgg_get_plugin_user_setting('not_exposable', $entity->owner_guid, 'expozeum') == false) { // We don't want to feature users, sites nor groups if (!elgg_instanceof($entity, 'object', 'hjalbumimage')) { return $menu; } if ($entity->expozeum) { $action = 'unexpozeum'; $icon = 'eye-alt'; //$text = 'unexpozeum'; } else { $action = 'expozeum'; $icon = 'eye'; //$text = 'expozeum'; } $menu[] = ElggMenuItem::factory(array('name' => 'expozeum', 'text' => elgg_view_icon($icon), 'href' => "action/expozeum_content/{$action}?guid={$entity->guid}", 'is_action' => true)); return $menu; } return $menu; }
/** * This functions performs actions when a wire post is created * * @param string $event 'create' * @param string $type 'object' * @param \ElggObject $object the ElggObject created * * @return void */ public static function triggerMentionNotificationEvent($event, $type, \ElggObject $object) { if (!elgg_instanceof($object, 'object', 'thewire')) { return; } // @todo replace with decent Elgg 2.0 notification event handling //send out notification to users mentioned in a wire post $usernames = []; preg_match_all("/\\@([A-Za-z0-9\\_\\.\\-]+)/i", $object->description, $usernames); if (empty($usernames)) { return; } $usernames = array_unique($usernames[0]); $params = ['object' => $object, 'action' => 'mention']; foreach ($usernames as $username) { $username = str_ireplace('@', '', $username); $user = get_user_by_username($username); if (empty($user) || $user->getGUID() == $object->getOwnerGUID()) { continue; } $setting = thewire_tools_get_notification_settings($user->getGUID()); if (empty($setting)) { continue; } $subject = elgg_echo('thewire_tools:notify:mention:subject'); $message = elgg_echo('thewire_tools:notify:mention:message', [$user->name, $object->getOwnerEntity()->name, elgg_normalize_url("thewire/search/@{$user->username}")]); notify_user($user->getGUID(), $object->getOwnerGUID(), $subject, $message, $params, $setting); } }
/** * Stripe related pages * * @param array $page * @param string $handler * @return boolean */ function stripe_page_handler($page, $handler) { gatekeeper(); $username = elgg_extract(0, $page, false); if ($username) { $user = get_user_by_username($username); } if (!elgg_instanceof($user) || !$user->canEdit()) { $user = elgg_get_logged_in_user_entity(); forward("{$handler}/{$user->username}"); } elgg_set_context('settings'); elgg_set_page_owner_guid($user->guid); elgg_push_breadcrumb(elgg_echo('stripe:billing'), 'billing'); $context = elgg_extract(1, $page, 'cards'); $action = elgg_extract(2, $page, 'all'); $view = "stripe/pages/{$context}/{$action}"; if (elgg_view_exists($view)) { $params = array('entity' => $user, 'id' => elgg_extract(3, $page, false), 'context' => $page); $title = elgg_echo("stripe:{$context}:{$action}"); $content = elgg_view($view, $params); $sidebar = elgg_view('stripe/sidebar', $params); $filter = elgg_view("stripe/filters/{$context}/{$action}", $params); } if ($content) { if (elgg_is_xhr()) { echo $content; } else { $layout = elgg_view_layout('content', array('title' => $title, 'content' => $content, 'sidebar' => $sidebar, 'filter' => $filter)); echo elgg_view_page($title, $layout); } return true; } return false; }
function group_member_entity_menu_handler($hook, $type, $returnvalue, $params) { $page_owner = elgg_get_page_owner_entity(); $user = elgg_get_logged_in_user_entity(); if (!$page_owner instanceof ElggGroup || empty($user) || $page_owner->owner_guid != $user->getGUID()) { return $returnvalue; } $result = $returnvalue; if (!empty($params) && is_array($params) && ($user = elgg_get_logged_in_user_entity())) { $entity = elgg_extract("entity", $params); if (elgg_instanceof($entity, "user") && $entity->getGUID() != $user->getGUID()) { if (!empty($result) && !is_array($result)) { $result = array($result); } elseif (empty($result)) { $result = array(); } if (check_entity_relationship($page_owner->getGUID(), "manager", $entity->getGUID())) { // pending request $result[] = ElggMenuItem::factory(array("name" => "set_group_manager", "text" => elgg_echo("group:setmanager"), "href" => "groups/setmanager/" . $page_owner->getGUID() . "/" . $entity->getGUID(), "is_action" => true, "priority" => 503)); } else { // add as friend $result[] = ElggMenuItem::factory(array("name" => "set_group_manager", "text" => elgg_echo("group:removemanager"), "href" => "groups/removemanager/" . $page_owner->getGUID() . "/" . $entity->getGUID(), "is_action" => true, "priority" => 503)); } } } return $result; }
/** * Add some menu items to the entity menu * * @param string $hook "register" * @param string $entity_type "menu:entity" * @param ElggMenuItem[] $returnvalue the current menu items * @param array $params supplied params * * @return ElggMenuItem[] */ public static function register($hook, $entity_type, $returnvalue, $params) { if (empty($params) || !is_array($params)) { return $returnvalue; } $entity = elgg_extract("entity", $params); if (empty($entity) || !elgg_instanceof($entity, "object", "blog")) { return $returnvalue; } // only published blogs if ($entity->status == "draft") { return $returnvalue; } if (!elgg_in_context("widgets") && elgg_is_admin_logged_in()) { $returnvalue[] = \ElggMenuItem::factory(array("name" => "blog-feature", "text" => elgg_echo("blog_tools:toggle:feature"), "href" => "action/blog_tools/toggle_metadata?guid=" . $entity->getGUID() . "&metadata=featured", "item_class" => empty($entity->featured) ? "" : "hidden", "is_action" => true, "priority" => 175)); $returnvalue[] = \ElggMenuItem::factory(array("name" => "blog-unfeature", "text" => elgg_echo("blog_tools:toggle:unfeature"), "href" => "action/blog_tools/toggle_metadata?guid=" . $entity->getGUID() . "&metadata=featured", "item_class" => empty($entity->featured) ? "hidden" : "", "is_action" => true, "priority" => 176)); } if ($entity->canComment()) { $returnvalue[] = \ElggMenuItem::factory(array("name" => "comments", "text" => elgg_view_icon("speech-bubble"), "title" => elgg_echo("comment:this"), "href" => $entity->getURL() . "#comments")); $comment_count = $entity->countComments(); if ($comment_count) { $returnvalue[] = \ElggMenuItem::factory(array("name" => "comments_count", "text" => $comment_count, "title" => elgg_echo("comments"), "href" => false)); } } return $returnvalue; }
/** * Make sure the last editor of a static page gets notified about a comment * * @param string $event 'create' * @param string $type 'object' * @param \ElggObject $object the object that was just created * * @return void */ public static function notifyLastEditor($event, $type, \ElggObject $object) { // check of this is a comment if (empty($object) || !elgg_instanceof($object, 'object', 'comment')) { return; } // is it a comment on a static page $container = $object->getContainerEntity(); if (empty($container) || !elgg_instanceof($container, 'object', 'static')) { return; } $comment_owner = $object->getOwnerEntity(); // get last revisor $ia = elgg_set_ignore_access(true); $revisions = $container->getAnnotations(['annotation_name' => 'static_revision', 'limit' => 1, 'reverse_order_by' => true]); $static_owner = $revisions[0]->getOwnerEntity(); elgg_set_ignore_access($ia); // don't notify yourself if ($static_owner->getGUID() == $comment_owner->getGUID()) { return; } // @see actions/comment/save $subject = elgg_echo('generic_comment:email:subject'); $message = elgg_echo('generic_comment:email:body', [$container->title, $comment_owner->name, $object->description, $container->getURL(), $comment_owner->name, $comment_owner->getURL()]); $params = ['object' => $object, 'action' => 'create']; notify_user($static_owner->getGUID(), $comment_owner->getGUID(), $subject, $message, $params); }
function gdocs_file_previewer_get_token($file, $timestamp) { if (!elgg_instanceof($file) || !is_numeric($timestamp)) { return false; } $secret = get_site_secret(); return sha1($file->guid . $secret . $timestamp); }
/** * Get the number of recurrences when user was awarded points for a given rule action on an object * * @param ElggUser $user * @param string $rule Rule name * @param int $time_lower Lower time constraint * @param int $time_upper Upper time constraint * @return int */ function get_user_recur_total($user, $rule, $time_lower = null, $time_upper = null) { if (empty($rule) || !elgg_instanceof($user, 'user')) { return 0; } $options = array('types' => 'object', 'subtypes' => HYPEGAMEMECHANICS_SCORE_SUBTYPE, 'container_guids' => $user->guid, 'created_time_lower' => $time_lower, 'created_time_upper' => $time_upper, 'metadata_name_value_pairs' => array(array('name' => 'rule', 'value' => $rule)), 'count' => true); return elgg_get_entities_from_metadata($options); }
function elgg_modifications_create_user_event_handler($event, $object_type, $object) { if (elgg_instanceof($object, "user")) { if (subsite_manager_on_subsite()) { $object->setPrivateSetting("digest_" . elgg_get_site_entity()->getOwnerGUID(), "none"); } } }