/** * 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"]); }
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; }
/** * Change search params for combined search * * @param string $hook the name of the hook * @param string $type the type of the hook * @param mixed $return_value current return value * @param array $params supplied params * * @return void|mixed */ public static function combinedParams($hook, $type, $return_value, $params) { $combined_search_type = elgg_extract('combined', $params); if (empty($combined_search_type)) { return; } switch ($combined_search_type) { case 'objects': $subtypes = elgg_extract('subtype', $return_value); if (empty($subtypes)) { return; } if (in_array(\ElggQuestion::SUBTYPE, $subtypes)) { // add answers $subtypes[] = \ElggAnswer::SUBTYPE; } $return_value['subtype'] = $subtypes; break; case 'all': $type_subtype_pairs = elgg_extract('type_subtype_pairs', $return_value); if (empty($type_subtype_pairs) || empty($type_subtype_pairs['object'])) { return; } if (in_array(\ElggQuestion::SUBTYPE, $type_subtype_pairs['object'])) { // add answers $type_subtype_pairs['object'][] = \ElggAnswer::SUBTYPE; } $return_value['type_subtype_pairs'] = $type_subtype_pairs; break; default: return; } return $return_value; }
/** * Logs the notification sent * * @param string $hook "send" * @param string $type "all" * @param mixed $return Result * @param array $params Hook params * @return mixed */ function notifications_log_sent_message($hook, $type, $return, $params) { list($hook_type, $method) = explode(':', $type); if ($hook_type != 'notification') { return; } $notification = elgg_extract('notification', $params); $recipient = $notification->getRecipient(); $sender = $notification->getSender(); $content = array('status' => $return === false ? 'failed' : 'sent', 'subject' => $notification->subject, 'summary' => $notification->summary, 'body' => $notification->body); $description = 'instant'; $event = elgg_extract('event', $params); if ($event) { $action = $event->getAction(); $actor = $event->getActor(); $object = $event->getObject(); $event_data = array('action' => $action, 'object' => is_callable(array($object, 'toObject')) ? $object->toObject() : array('guid' => $object->guid, 'id' => $object->id), 'actor' => is_callable(array($actor, 'toObject')) ? $actor->toObject() : array('guid' => $event->getActorGUID())); $content = array_merge($content, $event_data); $description = str_replace(':', '_', $event->getDescription()); } $name = implode('_', array($method, "TO-{$recipient->guid}", "FROM-{$sender->guid}", $description, time())); $dirname = elgg_get_config('dataroot') . '/notifications_log/'; if (!is_dir($dirname)) { mkdir($dirname, 0700, true); } $filename = "{$dirname}{$name}.json"; file_put_contents($filename, json_encode($content)); }
/** * Reorders todo to new position * * @param int $offset new position * * @return void */ public function moveToPosition($offset) { $current_order = $this->order; $options = array('type' => 'object', 'subtype' => $this::SUBTYPE, 'container_guid' => $this->container_guid, 'order_by_metadata' => array('name' => 'order', 'direction' => 'ASC', 'as' => 'integer'), 'limit' => false); $entities = elgg_get_entities_from_metadata($options); if (empty($entities)) { // nothing to do return; } $current_pos_entity = elgg_extract($offset, $entities); if (!$current_pos_entity) { return; } $new_order = $current_pos_entity->order; $forward = false; if ($current_order < $new_order) { $forward = true; } $this->order = $new_order; foreach ($entities as $entity) { if ($entity->guid == $this->guid) { continue; } if ($forward) { if ($entity->order <= $new_order) { $entity->order--; } } else { if ($entity->order >= $new_order) { $entity->order++; } } } }
/** * {@inheritdoc} */ public function handle(ElggEntity $entity) { $shortname = $this->getShortname(); $future_value = $_FILES[$shortname]; $value = $_FILES[$shortname]; $error_type = elgg_extract('error', $value); $has_uploaded_file = $error_type != UPLOAD_ERR_NO_FILE; if (!$has_uploaded_file) { return $entity; } $params = array('field' => $this, 'entity' => $entity, 'upload_name' => $shortname, 'future_value' => $future_value); // Allow plugins to prevent files from being uploaded if (!elgg_trigger_plugin_hook('handle:upload:before', 'prototyper', $params, true)) { return $entity; } $previous_upload = $this->getValues($entity); if ($previous_upload instanceof ElggFile) { $previous_upload->delete(); } $result = hypeApps()->uploader->handle($shortname, array('container_guid' => $entity->guid, 'origin' => 'prototyper', 'prototyper_field' => $shortname, 'access_id' => $entity->access_id)); /* @var $result ElggFile[] */ $future_value = $result[0]; $params = array('field' => $this, 'entity' => $entity, 'upload_name' => $shortname, 'value' => $future_value); elgg_trigger_plugin_hook('handle:upload:after', 'prototyper', $params, $result); return $entity; }
function entity_view_counter_get_configured_entity_types() { static $result; if (!isset($result)) { $result = false; // get registered entity types and plugin setting if (($registered_types = elgg_get_config("registered_entities")) && ($setting = elgg_get_plugin_setting("entity_types", "entity_view_counter"))) { $setting = json_decode($setting, true); $temp_result = array(); foreach ($registered_types as $type => $subtypes) { if (elgg_extract($type, $setting)) { $temp_result[$type] = array(); if (!empty($subtypes) && is_array($subtypes)) { foreach ($subtypes as $subtype) { if (elgg_extract($subtype, $setting[$type])) { $temp_result[$type][] = $subtype; } } } } } if (!empty($temp_result)) { $result = $temp_result; } } } return $result; }
/** * Set up entity menu for pool objects * * @param string $hook 'register' * @param string $type 'menu:entity' * @param ElggMenuItem[] $return * @param array $params * @return ElggMenuItem[] */ function pool_entity_menu($hook, $type, $return, $params) { $handler = elgg_extract('handler', $params, false); if ($handler != 'task_pool') { return $return; } if (elgg_is_logged_in()) { $entity = $params['entity']; $user_guid = elgg_get_logged_in_user_guid(); if ($entity->isMember($user_guid)) { $text = elgg_echo('pool:leave'); } else { $text = elgg_echo('pool:join'); } $return[] = ElggMenuItem::factory(array('name' => 'test', 'text' => "<span>{$text}</span>", 'href' => "action/pool/toggle_membership?pool_guid={$entity->guid}&user_guid={$user_guid}", 'priority' => 150, 'is_action' => true)); if (elgg_is_admin_logged_in()) { $return[] = ElggMenuItem::factory(array('name' => 'edit', 'text' => elgg_echo('edit'), 'href' => "admin/pool/save?guid={$entity->guid}")); $return[] = ElggMenuItem::factory(array('name' => 'delete', 'text' => elgg_view_icon('delete'), 'href' => "action/pool/admin/delete?guid={$entity->guid}", 'is_action' => true, 'confirm' => elgg_echo('question:areyousure'), 'priority' => 200)); if ($entity->countMembers()) { $return[] = ElggMenuItem::factory(array('name' => 'shift', 'text' => elgg_echo('pool:shift'), 'href' => "action/pool/shift?guid={$entity->guid}", 'priority' => 150, 'is_action' => true, 'confirm' => elgg_echo('question:areyousure'))); } } } return $return; }
/** * Build the named transaction based on an array of information from the route hook * * @param array $page_information the routing information * * @return void */ protected static function buildTransaction($page_information) { if (empty($page_information) || !is_array($page_information)) { return; } $transaction = []; $identifier = elgg_extract('identifier', $page_information); if (!empty($identifier)) { $transaction[] = $identifier; } // filter out usernames $usernames = self::getUsernamesToIgnore(); $segments = elgg_extract('segments', $page_information); if (!empty($segments) && is_array($segments)) { foreach ($segments as $segment) { if (is_numeric($segment) || in_array($segment, $usernames)) { $transaction[] = '*'; break; } else { $transaction[] = $segment; } } } newrelic_name_transaction('/' . implode('/', $transaction)); }
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; }
/** * Prevent outgoing e-mail to non test panel members * * @param string $hook the name of the hook * @param string $type the type of the hook * @param array $returnvalue the current return value * @param array $params supplied params * * @return void|false */ public static function email($hook, $type, $returnvalue, $params) { if (empty($returnvalue) || !is_array($returnvalue)) { // someone else already send the emails return; } if (!test_panel_limit_notifications()) { // don't limit e-mails return; } $to = elgg_extract('to', $returnvalue); if (empty($to) || !is_string($to)) { // don't know how to handle this return; } $to = EmailHandler::sanitizeEmail($to); elgg_log("Test panel processing: {$to}", 'INFO'); $allowed_emails = test_panel_get_panel_members_email_addresses(); if (empty($allowed_emails) || !is_array($allowed_emails)) { // nobody is allowed (shouldn't happen) return false; } if (!in_array($to, $allowed_emails)) { // user is not allowed to get e-mails elgg_log("Test panel blocked: {$to}", 'NOTICE'); return false; } // user is a panel member, so can receive e-mails }
/** * Handle /file_tools URLs * * @param array $page URL segments * * @return bool */ public static function fileTools($page) { switch (elgg_extract(0, $page)) { case 'list': elgg_ajax_gatekeeper(); $params = []; elgg_set_page_owner_guid(elgg_extract(1, $page)); $folder_guid = get_input('folder_guid', false); if ($folder_guid !== false) { $params['folder_guid'] = (int) $folder_guid; $params['draw_page'] = false; } if (isset($page[2])) { $params['folder_guid'] = (int) $page[2]; } echo elgg_view_resource('file_tools/file/list', $params); return true; break; case 'folder': switch (elgg_extract(1, $page)) { case 'new': elgg_set_page_owner_guid(elgg_extract(2, $page)); echo elgg_view_resource('file_tools/folder/new'); return true; break; case 'edit': $params = ['folder_guid' => (int) elgg_extract(2, $page)]; echo elgg_view_resource('file_tools/folder/edit', $params); return true; break; } break; } return false; }
/** * Extends the current config of htmlawed * * @param string $hook hookname * @param string $type hooktype * @param array $returnvalue returnvalue * @param array $params params * * @return void */ function ckeditor_extended_htmlawed_config($hook_name, $entity_type, $return_value, $params) { if (!is_array($return_value)) { return $return_value; } // Extend valid input elements $htmlawed_elements = elgg_get_plugin_setting('htmlawed_elements', 'ckeditor_extended'); if (!empty($htmlawed_elements)) { $ext_tags_array = explode(',', $htmlawed_elements); $elements = '*'; foreach ($ext_tags_array as $fulltag) { $fulltag = trim(str_replace(array('[', ']'), ' ', $fulltag)); $fulltag = explode(' ', $fulltag); $tag = $fulltag[0]; $elements .= '+' . $tag; } $return_value['elements'] = $elements; } $htmlawed_schemes = elgg_get_plugin_setting('htmlawed_schemes', 'ckeditor_extended'); if (!empty($htmlawed_schemes)) { $current_schemes = elgg_extract('schemes', $return_value, '*:http'); $htmlawed_schemes = $current_schemes . ',' . ltrim($htmlawed_schemes, ','); $return_value['schemes'] = $htmlawed_schemes; } return $return_value; }
/** * 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; }
/** * Add widget title link if Widget Manager is enabled. * * @param string $hook the name of the hook * @param string $type the type of the hook * @param array $return_value current return value * @param array $params supplied params * * @return void|string */ public static function widgetURL($hook, $type, $return_value, $params) { if (!empty($return_value)) { // url already set return; } if (elgg_is_logged_in()) { // already logged in return; } $widget = elgg_extract('entity', $params); if (!$widget instanceof \ElggWidget) { return; } if ($widget->handler !== 'simplesaml') { return; } $samlsource = $widget->samlsource; if (empty($samlsource) || $samlsource === 'all') { return; } if (!simplesaml_is_enabled_source($samlsource)) { return; } return "/saml/login/{$samlsource}"; }
/** * Messageboard dispatcher for flat message board. * Profile (and eventually group) widgets handle their own. * * URLs take the form of * User's messageboard: messageboard/owner/<username> * Y's history of posts on X's board: messageboard/owner/<X>/history/<Y> * New post: messageboard/add/<guid> (container: user or group) * Group messageboard: messageboard/group/<guid>/all (not implemented) * * @param array $page Array of page elements * @return bool */ function messageboard_page_handler($page) { $pages = dirname(__FILE__) . '/pages/messageboard'; switch ($page[0]) { case 'owner': //@todo if they have the widget disabled, don't allow this. $owner_name = elgg_extract(1, $page); $owner = get_user_by_username($owner_name); set_input('page_owner_guid', $owner->guid); $history = elgg_extract(2, $page); $username = elgg_extract(3, $page); if ($history && $username) { set_input('history_username', $username); } include "{$pages}/owner.php"; break; case 'add': $container_guid = elgg_extract(1, $page); set_input('container_guid', $container_guid); include "{$pages}/add.php"; break; case 'group': elgg_group_gatekeeper(); $owner_guid = elgg_extract(1, $page); set_input('page_owner_guid', $owner_guid); include "{$pages}/owner.php"; break; default: return false; } return true; }
/** * Get data from the csv configuration * * @param string $field (optional) the field to get, leave empty for all fields * * @return void|string|array */ public function getFormData($field = '') { if (!isset($this->form_data)) { $this->form_data = json_decode($this->description, true); } if (empty($this->form_data) || !is_array($this->form_data)) { return; } if (empty($field)) { return $this->form_data; } if ($field === 'type' || $field === 'subtype') { $type_subtype = $this->getFormData('type_subtype'); if (!is_string($type_subtype)) { return; } list($type, $subtype) = explode(':', $type_subtype); if ($field == 'type') { return $type; } else { return $subtype; } } return elgg_extract($field, $this->form_data); }
/** * Messageboard dispatcher for flat message board. * Profile (and eventually group) widgets handle their own. * * URLs take the form of * User's messageboard: messageboard/owner/<username> * Y's history of posts on X's board: messageboard/owner/<X>/history/<Y> * New post: messageboard/add/<guid> (container: user or group) * Group messageboard: messageboard/group/<guid>/all (not implemented) * * @param array $page Array of page elements * @return bool */ function messageboard_page_handler($page) { switch ($page[0]) { case 'owner': //@todo if they have the widget disabled, don't allow this. $owner_name = elgg_extract(1, $page); $owner = get_user_by_username($owner_name); set_input('page_owner_guid', $owner->guid); $history = elgg_extract(2, $page); $username = elgg_extract(3, $page); if ($history && $username) { set_input('history_username', $username); } echo elgg_view('resources/messageboard/owner'); break; case 'add': $container_guid = elgg_extract(1, $page); set_input('container_guid', $container_guid); echo elgg_view('resources/messageboard/add'); break; case 'group': elgg_group_gatekeeper(); $owner_guid = elgg_extract(1, $page); set_input('page_owner_guid', $owner_guid); echo elgg_view('resources/messageboard/owner'); break; default: return false; } return true; }
/** * Change the default notification message for comments * * @param string $hook the name of the hook * @param stirng $type the type of the hook * @param \Elgg\Notifications\Notification $return_value the current return value * @param array $params supplied values * * @return void|\Elgg\Notifications\Notification */ public static function prepareNotification($hook, $type, $return_value, $params) { if (!$return_value instanceof \Elgg\Notifications\Notification) { return; } if (empty($params) || !is_array($params)) { return; } $event = elgg_extract('event', $params); if (empty($event) || !$event instanceof \Elgg\Notifications\Event) { return; } // ignore access for now $ia = elgg_set_ignore_access(true); $comment = $event->getObject(); $actor = $event->getActor(); $object = $comment->getContainerEntity(); $language = elgg_extract('language', $params, get_current_language()); $recipient = elgg_extract('recipient', $params); $return_value->subject = elgg_echo('content_subscriptions:create:comment:subject', [$object->title], $language); $return_value->body = elgg_echo('content_subscriptions:create:comment:message', [$recipient->name, $actor->name, $object->title, $comment->description, $object->getURL()], $language); $return_value->summary = elgg_echo('content_subscriptions:create:comment:summary', [$object->title], $language); // restore access elgg_set_ignore_access($ia); return $return_value; }
/** * 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_tools_join_group_event($event, $type, $params) { static $auto_notification; // only load plugin setting once if (!isset($auto_notification)) { $auto_notification = false; if (elgg_get_plugin_setting("auto_notification", "group_tools") == "yes") { $auto_notification = true; } } if (!empty($params) && is_array($params)) { $group = elgg_extract("group", $params); $user = elgg_extract("user", $params); if ($user instanceof ElggUser && $group instanceof ElggGroup) { if ($auto_notification) { // enable email notification add_entity_relationship($user->getGUID(), "notifyemail", $group->getGUID()); if (elgg_is_active_plugin("messages")) { // enable site/messages notification add_entity_relationship($user->getGUID(), "notifysite", $group->getGUID()); } } // cleanup invites if (check_entity_relationship($group->getGUID(), "invited", $user->getGUID())) { remove_entity_relationship($group->getGUID(), "invited", $user->getGUID()); } // and requests if (check_entity_relationship($user->getGUID(), "membership_request", $group->getGUID())) { remove_entity_relationship($user->getGUID(), "membership_request", $group->getGUID()); } } } }
/** * After the question is updated in the databse make sure the answers have the same access_id * * @param string $event the name of the event * @param string $type the type of the event * @param \ElggObject $entity the affected object * * @return void */ public static function updateQuestion($event, $type, $entity) { if (!$entity instanceof \ElggQuestion) { return; } $org_attributes = $entity->getOriginalAttributes(); if (elgg_extract('access_id', $org_attributes) === null) { // access wasn't updated return; } // ignore access for this part $ia = elgg_set_ignore_access(true); // get all the answers for this question $answers = $entity->getAnswers(['limit' => false]); if (empty($answers)) { // restore access elgg_set_ignore_access($ia); return; } /* @var $answer \ElggAnswer */ foreach ($answers as $answer) { // update the access_id with the questions access_id $answer->access_id = $entity->access_id; $answer->save(); } // restore access elgg_set_ignore_access($ia); }
function hflts_page_handler($page) { if (elgg_extract(0, $page) === 'collective') { $content = elgg_view('hflts/collective', array('nAlternativas' => $page[1], 'nCriterios' => $page[2], 'nExpertos' => $page[3], 'G' => $page[4], 'import_file' => $page[5], 'weight_file' => $page[6])); $params = array('title' => 'DM con datos de samples/set_' . $page[5] . '.csv (' . $page[6] . ')', 'content' => $content, 'filter' => ''); $body = elgg_view_layout('content', $params); echo elgg_view_page('hflts', $body); return true; } set_input('username', $page[0]); //necesario $user = elgg_get_page_owner_entity(); // ej strem $guid = elgg_get_page_owner_guid(); // id de strem //aqui es donde tengo que filtrar por guid como en https://elgg.org/discussion/view/2268999/doubt-in-elgg-get-entities-from-metadata $valorations = elgg_get_entities_from_metadata(['type' => 'object', 'subtype' => 'evaluation_content', 'metadata_name_value_pairs' => array('name' => 'user_guid', 'value' => $guid), 'limit' => $vars['entity']->num_display, 'pagination' => false, 'order_by_metadata' => ['name' => 'state', 'direction' => 'ASC', 'as' => 'text']]); if (!$valorations) { $valorations = '<p class="mtm">' . elgg_echo('evaluationcontent:none') . '</p>'; } $content = elgg_view('hflts/driver', array('valorations' => $valorations)); $params = array('title' => 'Valoraciones de ' . $user->name, 'content' => $content, 'filter' => ''); $body = elgg_view_layout('content', $params); echo elgg_view_page('hflts', $body); }
/** * Extends the current config of htmlawed * * @param string $hook hookname * @param string $type hooktype * @param array $returnvalue returnvalue * @param array $params params * * @return void */ function ckeditor_extended_htmlawed_config($hook_name, $entity_type, $return_value, $params) { if (is_array($return_value)) { // Extend valid input elements $htmlawed_elements = elgg_get_plugin_setting("htmlawed_elements", "ckeditor_extended"); if (!empty($htmlawed_elements)) { $ext_tags_array = explode(",", $htmlawed_elements); $elements = "*"; foreach ($ext_tags_array as $fulltag) { $fulltag = trim(str_replace(array("[", "]"), " ", $fulltag)); $fulltag = explode(" ", $fulltag); $tag = $fulltag[0]; $opts = explode("|", $fulltag[1]); $elements .= "+" . $tag; } $return_value["elements"] = $elements; } $htmlawed_schemes = elgg_get_plugin_setting("htmlawed_schemes", "ckeditor_extended"); if (!empty($htmlawed_schemes)) { $current_schemes = elgg_extract("schemes", $return_value, "*:http"); $htmlawed_schemes = $current_schemes . "," . ltrim($htmlawed_schemes, ","); $return_value["schemes"] = $htmlawed_schemes; } } return $return_value; }
/** * Cleanup the cached inline images * * @param string $hook the name of the hook * @param string $type the type of the hook * @param mixed $return current return value * @param array $params supplied params * * @return mixed */ function html_email_handler_daily_cron_hook($hook, $type, $return, $params) { if (empty($params) || !is_array($params)) { return $return; } $cache_dir = elgg_get_config("dataroot") . "html_email_handler/image_cache/"; if (!is_dir($cache_dir)) { return $return; } $dh = opendir($cache_dir); if (empty($dh)) { return $return; } $max_lifetime = elgg_extract("time", $params, time()) - 24 * 60 * 60; while (($filename = readdir($dh)) !== false) { // make sure we have a file if (!is_file($cache_dir . $filename)) { continue; } $modified_time = filemtime($cache_dir . $filename); if ($modified_time > $max_lifetime) { continue; } // file is past lifetime, so cleanup unlink($cache_dir . $filename); } closedir($dh); return $return; }
/** * @param ElggPlugin $plugin * @return string */ public function outputPluginSettingsForm($plugin) { $translationPrefix = elgg_extract('translationPrefix', $this->options); $result = '<div>'; foreach ($this->fields as $name => $field) { $result .= '<div class="mbm">'; $result .= '<label>' . elgg_echo($translationPrefix . $name) . '</label> '; $description = elgg_extract('description', $field); if ($description) { $result .= '<div class="mbs">' . $description . '</div> '; } $params = $field; $type = elgg_extract('type', $field); $params['name'] = "params[{$name}]"; if ($plugin) { $params['value'] = $plugin->{$name}; } if (!isset($params['value']) || $params['value'] === null) { $params['value'] = elgg_extract('default', $field); } $result .= elgg_view('input/' . $type, $params); $result .= '</div>'; } $result .= '</div>'; return $result; }
/** * Add likes to entity menu at end of the menu */ function likes_entity_menu_setup($hook, $type, $return, $params) { if (elgg_in_context('widgets')) { return $return; } $entity = elgg_extract('entity', $params); if (!$entity instanceof \ElggEntity) { return $return; } $type = $entity->type; $subtype = $entity->getSubtype(); $likable = (bool) elgg_trigger_plugin_hook('likes:is_likable', "{$type}:{$subtype}", [], false); if (!$likable) { return $return; } if ($entity->canAnnotate(0, 'likes')) { $hasLiked = \Elgg\Likes\DataService::instance()->currentUserLikesEntity($entity->guid); // Always register both. That makes it super easy to toggle with javascript $return[] = ElggMenuItem::factory(array('name' => 'likes', 'href' => elgg_add_action_tokens_to_url("/action/likes/add?guid={$entity->guid}"), 'text' => elgg_view_icon('thumbs-up'), 'title' => elgg_echo('likes:likethis'), 'item_class' => $hasLiked ? 'hidden' : '', 'priority' => 1000, 'deps' => ['elgg/likes'])); $return[] = ElggMenuItem::factory(array('name' => 'unlike', 'href' => elgg_add_action_tokens_to_url("/action/likes/delete?guid={$entity->guid}"), 'text' => elgg_view_icon('thumbs-up-alt'), 'title' => elgg_echo('likes:remove'), 'item_class' => $hasLiked ? '' : 'hidden', 'priority' => 1000, 'deps' => ['elgg/likes'])); } // likes count $count = elgg_view('likes/count', array('entity' => $entity)); if ($count) { $options = array('name' => 'likes_count', 'text' => $count, 'href' => false, 'priority' => 1001, 'deps' => ['elgg/likes']); $return[] = ElggMenuItem::factory($options); } return $return; }
/** * Gestor de páginas * * @param array $page Array of page routing elements * @return bool */ function trip_companions_page_handler($page) { //system_message("page handler " . elgg_extract(0, $page)); // only logged in users can do things elgg_gatekeeper(); if (elgg_extract(0, $page) === 'add' && elgg_is_xhr()) { echo elgg_view('resources/evaluationcontent/add_form'); return true; } if (elgg_extract(0, $page) === 'import') { echo elgg_view('resources/trip_companions/add_form'); return true; } $friends = $groups = 0; switch ($page[0]) { case 'groups': $groups = 10; break; default: $friends = $groups = 10; break; } $page_owner = elgg_get_logged_in_user_entity(); elgg_set_page_owner_guid($page_owner->guid); elgg_set_context("trip_companions"); $content = elgg_view('resources/trip_companions/list', array('owner' => $page_owner, 'friends' => $friends, 'groups' => $groups)); if ($content) { echo $content; return true; } return false; }
/** * Save SEF data * * @param array $data Data * @return bool */ function seo_save_data($data) { $path = elgg_extract('path', $data); $sef_path = elgg_extract('sef_path', $data); if (!$path || !$sef_path) { return false; } $sef_hash = sha1($sef_path); $original_hash = sha1($path); $site = elgg_get_site_entity(); $file = new ElggFile(); $file->owner_guid = $site->guid; $file->setFilename("seo/{$sef_hash}.json"); $file->open('write'); $file->write(json_encode($data)); $file->close(); if ($sef_hash != $original_hash) { $file = new ElggFile(); $file->owner_guid = $site->guid; $file->setFilename("seo/{$original_hash}.json"); $file->open('write'); $file->write(json_encode($data)); $file->close(); } return true; }