/** * Performs a search of the elgg site * * @return array $results search result */ function site_search($query, $offset, $limit, $sort, $order, $search_type, $entity_type, $entity_subtype, $owner_guid, $container_guid) { $params = array('query' => $query, 'offset' => $offset, 'limit' => $limit, 'sort' => $sort, 'order' => $order, 'search_type' => $search_type, 'type' => $entity_type, 'subtype' => $entity_subtype, 'owner_guid' => $owner_guid, 'container_guid' => $container_guid); $types = get_registered_entity_types(); foreach ($types as $type => $subtypes) { $results = elgg_trigger_plugin_hook('search', $type, $params, array()); if ($results === FALSE) { // someone is saying not to display these types in searches. continue; } if ($results['count']) { foreach ($results['entities'] as $single) { //search matched critera /* $result['search_matched_title'] = $single->getVolatileData('search_matched_title'); $result['search_matched_description'] = $single->getVolatileData('search_matched_description'); $result['search_matched_extra'] = $single->getVolatileData('search_matched_extra'); */ if ($type == 'group' || $type == 'user') { $result['title'] = $single->name; } else { $result['title'] = $single->title; } $result['guid'] = $single->guid; $result['type'] = $single->type; $result['subtype'] = get_subtype_from_id($single->subtype); $result['avatar_url'] = get_entity_icon_url($single, 'small'); $return[$type] = $result; } } } return $return; }
/** * Determines if $viewer has access to $user's friends list * * @param ElggUser $user User whose friends are to be displayed * @param ElggUser $viewer Viewer * @return bool */ function user_friends_can_view_friends(ElggUser $user, ElggUser $viewer = null) { if (!isset($viewer)) { $viewer = elgg_get_logged_in_user_entity(); } $permission = false; if ($viewer && elgg_check_access_overrides($viewer->guid)) { $permission = true; } $setting = elgg_get_plugin_user_setting('friend_list_visibility', $user->guid, 'user_friends'); if (!isset($setting)) { $setting = elgg_get_plugin_setting('friend_list_visibility', 'user_friends', ACCESS_PUBLIC); } switch ((int) $setting) { case ACCESS_PRIVATE: $permission = $viewer && $user->canEdit($viewer->guid); break; case ACCESS_FRIENDS: $permission = $viewer && $user->isFriendsWith($viewer->guid); break; case ACCESS_LOGGED_IN: $permission = $viewer; break; case ACCESS_PUBLIC: $permission = true; break; } $params = array('viewer' => $viewer, 'user' => $user); return elgg_trigger_plugin_hook('permissions_check:view_friends_list', 'user', $params, $permission); }
/** * Serves pages for upload and embed. * * @param $page */ function embed_page_handler($page) { if (!isset($page[0])) { $page[0] = 'embed'; } switch ($page[0]) { case 'upload': echo elgg_view('embed/upload'); break; case 'embed': default: // trigger hook to get section tabs // use views for embed/section/ // listing // item // default to embed/listing | item if not found. // @todo trigger for all right now. If we categorize these later we can trigger // for certain categories. $sections = elgg_trigger_plugin_hook('embed_get_sections', 'all', NULL, array()); $upload_sections = elgg_trigger_plugin_hook('embed_get_upload_sections', 'all', NULL, array()); elgg_sort_3d_array_by_value($sections, 'name'); elgg_sort_3d_array_by_value($upload_sections, 'name'); $active_section = get_input('active_section', NULL); $internal_name = get_input('internal_name', NULL); echo elgg_view('embed/embed', array('sections' => $sections, 'active_section' => $active_section, 'upload_sections' => $upload_sections, 'internal_name' => $internal_name)); break; } // exit because this is in a modal display. exit; }
/** * Cron job */ function garbagecollector_cron($hook, $entity_type, $returnvalue, $params) { echo elgg_echo('garbagecollector'); // Garbage collect metastrings echo elgg_echo('garbagecollector:gc:metastrings'); if (_elgg_delete_orphaned_metastrings() !== false) { echo elgg_echo('garbagecollector:ok'); } else { echo elgg_echo('garbagecollector:error'); } echo "\n"; // Now, because we are nice, trigger a plugin hook to let other plugins do some GC $rv = true; $period = elgg_get_plugin_setting('period', 'garbagecollector'); elgg_trigger_plugin_hook('gc', 'system', array('period' => $period)); // Now we optimize all tables $tables = garbagecollector_get_tables(); foreach ($tables as $table) { echo elgg_echo('garbagecollector:optimize', array($table)); if (garbagecollector_optimize_table($table) !== false) { echo elgg_echo('garbagecollector:ok'); } else { echo elgg_echo('garbagecollector:error'); } echo "\n"; } echo elgg_echo('garbagecollector:done'); }
/** * @param string $text * @param array $context info to pass to the plugin hooks * * @return string * * @throws Exception */ public function process($text, $context = array()) { $tokens = $this->tokenizer->getTokens($text); // allow processors that might need to see all the tokens at once $tokens = elgg_trigger_plugin_hook("prepare:tokens", "ecml", $context, $tokens); if (!is_array($tokens)) { throw new Exception(elgg_echo('ecml:Exception:InvalidTokenList')); } // process tokens in isolation $output = ''; foreach ($tokens as $token) { if (is_string($token)) { $output .= $token; } elseif ($token instanceof Elgg_Ecml_Token) { /* @var Elgg_Ecml_Token $token */ if ($token->isText) { $output .= $token->content; } else { $params = array_merge($context, array('keyword' => $token->keyword, 'attributes' => $token->attrs)); $output .= elgg_trigger_plugin_hook("render:{$token->keyword}", "ecml", $params, $token->content); } } else { throw new Exception(elgg_echo('ecml:Exception:InvalidToken')); } } return $output; }
/** * Encode a location into a latitude and longitude, caching the result. * * Works by triggering the 'geocode' 'location' plugin * hook, and requires a geocoding plugin to be installed. * * @param string $location The location, e.g. "London", or "24 Foobar Street, Gotham City" * @return string|false */ function elgg_geocode_location($location) { global $CONFIG; if (is_array($location)) { return false; } $location = sanitise_string($location); // Look for cached version $query = "SELECT * from {$CONFIG->dbprefix}geocode_cache WHERE location='{$location}'"; $cached_location = get_data_row($query); if ($cached_location) { return array('lat' => $cached_location->lat, 'long' => $cached_location->long); } // Trigger geocode event if not cached $return = false; $return = elgg_trigger_plugin_hook('geocode', 'location', array('location' => $location), $return); // If returned, cache and return value if ($return && is_array($return)) { $lat = (double) $return['lat']; $long = (double) $return['long']; // Put into cache at the end of the page since we don't really care that much $query = "INSERT DELAYED INTO {$CONFIG->dbprefix}geocode_cache " . " (location, lat, `long`) VALUES ('{$location}', '{$lat}', '{$long}')" . " ON DUPLICATE KEY UPDATE lat='{$lat}', `long`='{$long}'"; execute_delayed_write_query($query); } return $return; }
public function __construct() { $types = get_registered_entity_types(); $custom_types = elgg_trigger_plugin_hook('search_types', 'get_types', $params, array()); $types['object'] = array_merge($types['object'], $custom_types); $this->types = $types; }
/** * Track Elgg events if the settings allows this * * @param string $category category of the event * @param string $action the action of the event * @param string $label optional label for tracking * * @return void */ function analytics_track_event($category, $action, $label = '') { if (!analytics_google_track_events_enabled()) { // tracking is not enabled return; } if (empty($category) || empty($action)) { // invalid input return; } $params = ['category' => $category, 'action' => $action, 'label' => $label]; if (!elgg_trigger_plugin_hook('track_event', 'analytics', $params, true)) { // don't track this event return; } if (!isset($_SESSION['analytics'])) { $_SESSION['analytics'] = []; } if (!isset($_SESSION['analytics']['events'])) { $_SESSION['analytics']['events'] = []; } $t_event = ['category' => $category, 'action' => $action]; if (!empty($label)) { $t_event['label'] = $label; } $_SESSION['analytics']['events'][] = $t_event; }
function widget_manager_widget_url_handler($widget) { $result = false; if ($widget instanceof ElggWidget) { /* plugins should use the following hook for setting the correct widget title */ $result = elgg_trigger_plugin_hook("widget_url", "widget_manager", array("entity" => $widget), false); if (empty($result)) { $handler = $widget->handler; $widgettypes = elgg_get_config("widgets"); if (isset($widgettypes->handlers[$handler]->link)) { $link = $widgettypes->handlers[$handler]->link; } if (!empty($link)) { /* this substitution loop will be deprecated in a future version */ $owner = $widget->getOwnerEntity(); if ($owner instanceof ElggSite) { if (elgg_is_logged_in()) { // index widgets sometimes use usernames in widget titles $owner = elgg_get_logged_in_user_entity(); } } /* Let's do some basic substitutions to the link */ /* [USERNAME] */ $link = preg_replace('#\\[USERNAME\\]#', $owner->username, $link); /* [GUID] */ $link = preg_replace('#\\[GUID\\]#', $owner->getGUID(), $link); /* [BASEURL] */ $link = preg_replace('#\\[BASEURL\\]#', elgg_get_site_url(), $link); $result = $link; } } } return $result; }
/** * Push a tweet to twitter. * * @param unknown_type $hook * @param unknown_type $entity_type * @param unknown_type $returnvalue * @param unknown_type $params */ function twitter_api_tweet($hook, $entity_type, $returnvalue, $params) { static $plugins; if (!$plugins) { $plugins = elgg_trigger_plugin_hook('plugin_list', 'twitter_service', NULL, array()); } // ensure valid plugin if (!in_array($params['plugin'], $plugins)) { return NULL; } // check admin settings $consumer_key = elgg_get_plugin_setting('consumer_key', 'twitter_api'); $consumer_secret = elgg_get_plugin_setting('consumer_secret', 'twitter_api'); if (!($consumer_key && $consumer_secret)) { return NULL; } // check user settings $user_id = elgg_get_logged_in_user_guid(); $access_key = elgg_get_plugin_user_setting('access_key', $user_id, 'twitter_api'); $access_secret = elgg_get_plugin_user_setting('access_secret', $user_id, 'twitter_api'); if (!($access_key && $access_secret)) { return NULL; } // send tweet $api = new TwitterOAuth($consumer_key, $consumer_secret, $access_key, $access_secret); $response = $api->post('statuses/update', array('status' => $params['message'])); return TRUE; }
/** * Handles voting on an entity * * @param integer $guid The entity guid being voted on * @param integer $vote The vote * @return string A status message to be returned to the client */ function elggx_fivestar_vote($guid, $vote) { $entity = get_entity($guid); $annotation_owner = elgg_get_logged_in_user_guid(); $msg = null; if ($annotation = elgg_get_annotations(array('guid' => $entity->guid, 'type' => $entity->type, 'annotation_name' => 'fivestar', 'annotation_owner_guid' => $annotation_owner, 'limit' => 1))) { if ($vote == 0 && (int) elgg_get_plugin_setting('change_cancel', 'elggx_fivestar', 1)) { if (!elgg_trigger_plugin_hook('elggx_fivestar:cancel', 'all', array('entity' => $entity), false)) { elgg_delete_annotations(array('annotation_id' => $annotation[0]->id)); $msg = elgg_echo('elggx_fivestar:deleted'); } } else { if ((int) elgg_get_plugin_setting('change_cancel', 'elggx_fivestar', 1)) { update_annotation($annotation[0]->id, 'fivestar', $vote, 'integer', $annotation_owner, 2); $msg = elgg_echo('elggx_fivestar:updated'); } else { $msg = elgg_echo('elggx_fivestar:nodups'); } } } else { if ($vote > 0) { if (!elgg_trigger_plugin_hook('elggx_fivestar:vote', 'all', array('entity' => $entity), false)) { $entity->annotate('fivestar', $vote, 2, $annotation_owner); } } else { $msg = elgg_echo('elggx_fivestar:novote'); } } elggx_fivestar_setRating($entity); return $msg; }
/** * dropzone/upload action handler * @return array */ public function handleUploads() { $subtype = get_input('subtype'); if (!$subtype) { $subtype = elgg_get_plugin_setting('default_upload_subtype', 'hypeDropzone', 'file'); } $uploads = $this->saveUploadedFiles('dropzone', ['owner_guid' => elgg_get_logged_in_user_guid(), 'container_guid' => get_input('container_guid') ?: ELGG_ENTITIES_ANY_VALUE, 'subtype' => $subtype, 'access_id' => ACCESS_PRIVATE, 'origin' => get_input('origin', 'dropzone')]); $output = array(); foreach ($uploads as $upload) { $messages = array(); $success = true; if ($upload->error) { $messages[] = $upload->error; $success = false; ${$guid} = false; } else { $file = $upload->file; $guid = $file->guid; $html = elgg_view('input/hidden', array('name' => get_input('input_name', 'guids[]'), 'value' => $file->guid)); } $file_output = array('messages' => $messages, 'success' => $success, 'guid' => $guid, 'html' => $html); $output[] = elgg_trigger_plugin_hook('upload:after', 'dropzone', array('upload' => $upload), $file_output); } return $output; }
/** * Routes the request to a registered page handler * * This function triggers a plugin hook `'route', $identifier` so that plugins can * modify the routing or handle a request. * * @param Elgg_Http_Request $request The request to handle. * @return boolean Whether the request was routed successfully. * @access private */ public function route(Elgg_Http_Request $request) { $segments = $request->getUrlSegments(); if ($segments) { $identifier = array_shift($segments); } else { $identifier = ''; // this plugin hook is deprecated. Use elgg_register_page_handler() // to register for the '' (empty string) handler. // allow plugins to override the front page (return true to indicate // that the front page has been served) $result = elgg_trigger_plugin_hook('index', 'system', null, false); if ($result === true) { elgg_deprecated_notice("The 'index', 'system' plugin has been deprecated. See elgg_front_page_handler()", 1.9); exit; } } // return false to stop processing the request (because you handled it) // return a new $result array if you want to route the request differently $result = array('identifier' => $identifier, 'handler' => $identifier, 'segments' => $segments); $result = $this->hooks->trigger('route', $identifier, null, $result); if ($result === false) { return true; } $identifier = $result['identifier']; $segments = $result['segments']; $handled = false; if (isset($this->handlers[$identifier]) && is_callable($this->handlers[$identifier])) { $function = $this->handlers[$identifier]; $handled = call_user_func($function, $segments, $identifier); } return $handled || headers_sent(); }
/** * This method is called when a users points are updated. * We check to see what the users current balance is and * assign the appropriate badge. */ function badges_userpoints($hook, $type, $return, $params) { if ($params['entity']->badges_locked) { return true; } $points = $params['entity']->userpoints_points; $badge = get_entity($params['entity']->badges_badge); $options = array('type' => 'object', 'subtype' => 'badge', 'limit' => false, 'order_by_metadata' => array('name' => 'badges_userpoints', 'direction' => DESC, 'as' => integer)); $options['metadata_name_value_pairs'] = array(array('name' => 'badges_userpoints', 'value' => $points, 'operand' => '<=')); $entities = elgg_get_entities_from_metadata($options); if ((int) elgg_get_plugin_setting('lock_high', 'elggx_badges')) { if ($badge->badges_userpoints > $entities[0]->badges_userpoints) { return true; } } if ($badge->guid != $entities[0]->guid) { $params['entity']->badges_badge = $entities[0]->guid; if (!elgg_trigger_plugin_hook('badges:update', 'object', array('entity' => $user), true)) { $params['entity']->badges_badge = $badge->guid; return false; } // Announce it on the river $user_guid = $params['entity']->getGUID(); elgg_delete_river(array("view" => 'river/object/badge/assign', "subject_guid" => $user_guid, "object_guid" => $user_guid)); elgg_delete_river(array("view" => 'river/object/badge/award', "subject_guid" => $user_guid, "object_guid" => $user_guid)); elgg_create_river_item(array('view' => 'river/object/badge/award', 'action_type' => 'award', 'subject_guid' => $user_guid, 'object_guid' => $user_guid)); } return true; }
function crontrigger_trigger($period) { $now = time(); $params = array(); $params['time'] = $now; elgg_trigger_plugin_hook('cron', $period, $params, ""); }
/** * Routes the request to a registered page handler * * This function sets the context based on the handler name (first segment of the * URL). It also triggers a plugin hook 'route', $handler so that plugins can * modify the routing or handle a request. * * @param string $handler The name of the handler type (eg 'blog') * @param array $page The parameters to the page, as an array (exploded by '/' slashes) * * @return bool * @access private */ function page_handler($handler, $page) { global $CONFIG; elgg_set_context($handler); $page = explode('/', $page); // remove empty array element when page url ends in a / (see #1480) if ($page[count($page) - 1] === '') { array_pop($page); } // return false to stop processing the request (because you handled it) // return a new $params array if you want to route the request differently $params = array('handler' => $handler, 'segments' => $page); $params = elgg_trigger_plugin_hook('route', $handler, NULL, $params); if ($params === false) { return true; } $handler = $params['handler']; $page = $params['segments']; $result = false; if (isset($CONFIG->pagehandler) && !empty($handler) && isset($CONFIG->pagehandler[$handler])) { $function = $CONFIG->pagehandler[$handler]; $result = call_user_func($function, $page, $handler); } return $result || headers_sent(); }
/** * Returns display properties of the verb * @return array */ private function getDisplay() { $key = "tincan:verb:{$this->verb}"; $string = elgg_echo($key, array(), 'en'); $display = array('en' => $key == $string ? $this->verb : $string); return elgg_trigger_plugin_hook('tincan:display', 'verb', array('verb' => $this->verb), $display); }
/** * hook called on route, all * check if $returnvalue['handler'] to see if we need to replace it * if the handler is an original handler, we want to foward it to the new url * * @param type $hook * @param type $type * @param type $returnvalue * @param type $params * @return array */ function router($hook, $type, $returnvalue, $params) { if (elgg_get_config('pagehandler_hijack')) { return $returnvalue; } $handlers = get_replacement_handlers(); if (in_array($returnvalue['handler'], array_keys($handlers))) { // we have been given an old handler -> we should forward to the replacement // probably from an old link or something $currenturl = current_page_url(); //get everything after the pagehandler $afterhandler = str_replace(elgg_get_site_url() . $returnvalue['handler'], "", $currenturl); $newurl = elgg_get_site_url() . $handlers[$returnvalue['handler']] . $afterhandler; // forward to the new url forward($newurl); } if (in_array($returnvalue['handler'], $handlers)) { // we need to do something about it // get the original handler $original = array_search($returnvalue['handler'], $handlers); if (!empty($original)) { // reset the context for non-hijack aware code elgg_set_context($original); // let the system load content for the original handler $returnvalue['handler'] = $original; $returnvalue['identifier'] = $original; // set a flag so we don't infinite loop ourselves in route hooks elgg_set_config('pagehandler_hijack', true); return elgg_trigger_plugin_hook('route', $original, null, $returnvalue); } } }
/** * Returns a field collection * * @param mixed $entity ElggEntity or an array of entity attributes * @param string $action Action name (used as a plugin hook type) * @param array $params Additional context params to pass to the hook * @return \hypeJunction\Prototyper\Elements\FieldCollection */ public function fields($entity = array(), $action = 'all', array $params = array()) { $fieldCollection = array(); $entity = $this->entityFactory->build($entity); if ($entity instanceof \ElggEntity) { $params['entity'] = $entity; $fields = (array) elgg_trigger_plugin_hook('prototype', $action, $params, array()); $attribute_names = $this->entityFactory->getAttributeNames($entity); if (!$entity->guid) { $fields['type'] = array('type' => 'hidden'); $fields['subtype'] = array('type' => 'hidden'); $fields['owner_guid'] = array('type' => 'hidden'); $fields['container_guid'] = array('type' => 'hidden'); } else { $fields['guid'] = array('type' => 'hidden'); } foreach ($fields as $shortname => $field) { $field['entity_type'] = $entity->getType(); $field['entity_subtype'] = $entity->getSubtype(); if (empty($field['shortname'])) { $field['shortname'] = $shortname; } if (in_array($shortname, $attribute_names)) { $field['data_type'] = 'attribute'; $field['class_name'] = Elements\AttributeField::CLASSNAME; } $fieldObj = $this->fieldFactory->build($field); if ($fieldObj instanceof Elements\Field) { $fieldCollection[] = $fieldObj; } } } return new Elements\FieldCollection($fieldCollection); }
/** * {@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; }
public function execute() { $this->uploads = hypeApps()->uploader->handle('dropzone', array('subtype' => $this->subtype, 'container_guid' => $this->container_guid, 'access_id' => ACCESS_PRIVATE)); $output = array(); foreach ($this->uploads as $upload) { $messages = array(); $success = true; if ($upload->error) { $messages[] = $upload->error; $success = false; $guid = false; } else { $file = $upload->file; if (!$file instanceof \ElggEntity) { $messages[] = elgg_echo('dropzone:file_not_entity'); $success = false; } else { $guid = $file->getGUID(); $html = elgg_view('input/hidden', array('name' => $this->input_name, 'value' => $file->getGUID())); } } $file_output = array('messages' => $messages, 'success' => $success, 'guid' => $guid, 'html' => $html); $output[] = elgg_trigger_plugin_hook('upload:after', 'dropzone', array('upload' => $upload), $file_output); } $this->result->output = json_encode($output); }
/** * Cron handler * * @param array $page Pages * * @return void */ function cron_page_handler($page) { global $CONFIG; if (!isset($page[0])) { forward(); } $period = strtolower($page[0]); $allowed_periods = array('minute', 'fiveminute', 'fifteenmin', 'halfhour', 'hourly', 'daily', 'weekly', 'monthly', 'yearly', 'reboot'); if (!in_array($period, $allowed_periods)) { throw new CronException(elgg_echo('CronException:unknownperiod', array($period))); } // Get a list of parameters $params = array(); $params['time'] = time(); foreach ($CONFIG->input as $k => $v) { $params[$k] = $v; } // Data to return to $std_out = ""; $old_stdout = ""; ob_start(); $old_stdout = elgg_trigger_plugin_hook('cron', $period, $params, $old_stdout); $std_out = ob_get_clean(); echo $std_out . $old_stdout; }
/** * imagick watermarking * * @param string $filename * @return bool */ function tp_imagick_watermark($filename) { $watermark_text = elgg_get_plugin_setting('watermark_text', 'tidypics'); if (!$watermark_text) { return false; } // plugins can do their own watermark and return false to prevent this function from running if (elgg_trigger_plugin_hook('tp_watermark', 'imagick', $filename, true) === false) { return true; } $owner = get_loggedin_user(); $watermark_text = tp_process_watermark_text($watermark_text, $owner); $img = new Imagick($filename); $img->readImage($image); $draw = new ImagickDraw(); //$draw->setFont(""); $draw->setFontSize(28); $draw->setFillOpacity(0.5); $draw->setGravity(Imagick::GRAVITY_SOUTH); $img->annotateImage($draw, 0, 0, 0, $watermark_text); if ($img->writeImage($filename) != true) { $img->destroy(); return false; } $img->destroy(); return true; }
function loginrequired_init() { global $CONFIG; // No need to do all the checking below if the user is already logged in... performance is key :) // if (elgg_is_logged_in()) return; elgg_extend_view('css/elgg', 'loginrequired/css'); // elgg_unextend_view('page/elements/header', 'search/header'); elgg_register_plugin_hook_handler('index', 'system', 'loginrequired_index', 1); elgg_register_plugin_hook_handler('login_required', 'login_required', 'login_required_default_allowed_list'); // Get the current page URL without any ? & parameters... this is required for the registration page to work properly $current_url = current_page_url(); $parameters_start = strrpos($current_url, '?'); if ($parameters_start) { $current_url = substr($current_url, 0, $parameters_start); } // Always allow index page if ($current_url == $CONFIG->url) { return; } $allow = array(); // Allow should have pages $allow[] = '_graphics'; $allow[] = 'action/login'; $allow[] = 'register'; $allow[] = 'action/register'; $allow[] = 'forgotpassword'; $allow[] = 'resetpassword'; $allow[] = 'action/user/requestnewpassword'; $allow[] = 'action/user/passwordreset'; $allow[] = 'action/security/refreshtoken'; $allow[] = 'ajax/view/js/languages'; $allow[] = 'upgrade\\.php'; $allow[] = 'xml-rpc\\.php'; $allow[] = 'mt/mt-xmlrpc\\.cgi'; $allow[] = 'css/.*'; $allow[] = 'js/.*'; $allow[] = 'cache/css/.*'; $allow[] = 'cache/js/.*'; // Allow other plugin developers to edit the array values $add_allow = elgg_trigger_plugin_hook('login_required', 'login_required'); // If more URL's are added... merge both with original list if (is_array($add_allow)) { $allow = array_merge($allow, $add_allow); } // Any public_pages defined via Elgg's walled garden plugin hook? $plugins = elgg_trigger_plugin_hook('public_pages', 'walled_garden', NULL, array()); // If more URL's are added... merge both with original list if (is_array($plugins)) { $allow = array_merge($allow, $plugins); } // Check if current page is in allowed list... otherwise redirect to login foreach ($allow as $public) { $pattern = "`^{$CONFIG->url}{$public}/*\$`i"; if (preg_match($pattern, $current_url)) { return; } } gatekeeper(); }
/** * Register list-like views to be wrapped for ajax pagination * @return void */ function register_view_hook_handlers() { $defaults = array('page/components/list', 'page/components/gallery', 'page/components/ajax_list'); $views = elgg_trigger_plugin_hook('get_views', 'framework:lists', null, $defaults); foreach ($views as $view) { elgg_register_plugin_hook_handler('view', $view, __NAMESPACE__ . '\\wrap_list_view_hook'); } }
/** * Check if avatars enabled for entities of given type and subtype * * @param string $type Entity type * @param string $subtype Entity subtype * @return bool */ function avatars_enabled($type, $subtype = null) { $hook_type = $type; if ($subtype) { $hook_type = "{$type}:{$subtype}"; } return elgg_trigger_plugin_hook('avatars:enabled', $hook_type, null, false); }
function mentions_get_views() { // allow plugins to add additional views to be processed for usernames $views = array('output/longtext'); $views = elgg_trigger_plugin_hook('get_views', 'mentions', null, $views); foreach ($views as $view) { elgg_register_plugin_hook_handler('view', $view, 'mentions_rewrite'); } }
/** * Prepare menu * Returns an array of section => items pairs * * @param ElggMenuItem[] $menu Menu * @param array $params Menu params * @return array */ function menus_api_prepare_menu($menu, array $params = []) { $menu_name = elgg_extract('name', $params); $sort_by = elgg_extract('sort_by', $params, 'text'); $builder = new \ElggMenuBuilder($menu); $params['menu'] = $builder->getMenu($sort_by); $params['selected_item'] = $builder->getSelected(); return elgg_trigger_plugin_hook('prepare', "menu:{$menu_name}", $params, $params['menu']); }
/** * Init * @return void */ function webhooks_init() { $events = array('create', 'created', 'update', 'delete', 'enable', 'disable', 'join', 'leave', 'login', 'profileudpate'); $events = elgg_trigger_plugin_hook('events', 'webhooks', null, $events); foreach ($events as $event) { elgg_register_event_handler($event, 'all', 'webhooks_send', 999); elgg_register_event_handler("{$event}:after", 'all', 'webhooks_send', 999); } }
/** * Handle search hook, to include answers in the same set as questions * * @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 handleQuestionsSearch($hook, $type, $return_value, $params) { if (empty($params) || !is_array($params)) { return; } unset($params['subtype']); $params['subtypes'] = [\ElggAnswer::SUBTYPE, \ElggQuestion::SUBTYPE]; return elgg_trigger_plugin_hook('search', 'object', $params, $return_value); }