/** * Start the site pages plugin. */ function sitepages_init() { require_once dirname(__FILE__) . '/sitepages_functions.php'; global $CONFIG; // register our subtype run_function_once('sitepages_runonce'); // Register a page handler, so we can have nice URLs register_page_handler('sitepages', 'sitepages_page_handler'); // Register a URL handler for external pages register_entity_url_handler('sitepages_url', 'object', 'sitepages'); elgg_extend_view('footer/links', 'sitepages/footer_menu'); elgg_extend_view('metatags', 'sitepages/metatags'); // Replace the default index page if user has requested if (get_plugin_setting('ownfrontpage', 'sitepages') == 'yes') { register_plugin_hook('index', 'system', 'sitepages_custom_index'); } // parse views for keywords register_plugin_hook('display', 'view', 'sitepages_parse_view'); // register the views we want to parse for the keyword replacement // right now this is just the custom front page, but we can // expand it to the other pages later. $CONFIG->sitepages_parse_views = array('sitepages/custom_frontpage'); // an example of how to register and respond to the get_keywords trigger register_plugin_hook('get_keywords', 'sitepages', 'sitepages_keyword_hook'); // grab the list of keywords and their views from plugins if ($keywords = trigger_plugin_hook('get_keywords', 'sitepages', NULL, array())) { $CONFIG->sitepages_keywords = $keywords; } register_action("sitepages/add", FALSE, $CONFIG->pluginspath . "sitepages/actions/add.php"); register_action("sitepages/addfront", FALSE, $CONFIG->pluginspath . "sitepages/actions/addfront.php"); register_action("sitepages/addmeta", FALSE, $CONFIG->pluginspath . "sitepages/actions/addmeta.php"); register_action("sitepages/edit", FALSE, $CONFIG->pluginspath . "sitepages/actions/edit.php"); register_action("sitepages/delete", FALSE, $CONFIG->pluginspath . "sitepages/actions/delete.php"); }
/** * Cron job * */ function garbagecollector_cron($hook, $entity_type, $returnvalue, $params) { global $CONFIG; echo elgg_echo('garbagecollector'); // Garbage collect metastrings echo elgg_echo('garbagecollector:gc:metastrings'); if (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 = get_plugin_setting('period', 'garbagecollector'); trigger_plugin_hook('gc', 'system', array('period' => $period)); // Now we optimize all tables $tables = get_db_tables(); foreach ($tables as $table) { echo sprintf(elgg_echo('garbagecollector:optimize'), $table); if (optimize_table($table) !== false) { echo elgg_echo('garbagecollector:ok'); } else { echo elgg_echo('garbagecollector:error'); } echo "\n"; } echo elgg_echo('garbagecollector:done'); }
/** * This function loads a set of default fields into the profile, then triggers a hook letting other plugins to edit * add and delete fields. * * Note: This is a secondary system:init call and is run at a super low priority to guarantee that it is called after all * other plugins have initialised. */ function profile_fields_setup() { global $CONFIG; $profile_defaults = array('description' => 'longtext', 'briefdescription' => 'text', 'location' => 'tags', 'interests' => 'tags', 'skills' => 'tags', 'contactemail' => 'email', 'phone' => 'text', 'mobile' => 'text', 'website' => 'url', 'twitter' => 'text'); // TODO: Have an admin interface for this $n = 0; $loaded_defaults = array(); while ($translation = get_plugin_setting("admin_defined_profile_{$n}", 'profile')) { // Add a translation add_translation(get_current_language(), array("profile:admin_defined_profile_{$n}" => $translation)); // Detect type $type = get_plugin_setting("admin_defined_profile_type_{$n}", 'profile'); if (!$type) { $type = 'text'; } // Set array $loaded_defaults["admin_defined_profile_{$n}"] = $type; $n++; } if (count($loaded_defaults)) { $CONFIG->profile_using_custom = true; $profile_defaults = $loaded_defaults; } $CONFIG->profile = trigger_plugin_hook('profile:fields', 'profile', NULL, $profile_defaults); // register any tag metadata names foreach ($CONFIG->profile as $name => $type) { if ($type == 'tags') { elgg_register_tag_metadata_name($name); // register a tag name translation add_translation(get_current_language(), array("tag_names:{$name}" => elgg_echo("profile:{$name}"))); } } }
function homepage_cms_page_handler($page) { if (!isset($page[0])) { $page[0] = 'all'; } $page_type = $page[0]; $base_plugin_pages = elgg_get_plugins_path() . 'homepage_cms_ed/pages/homepage_cms'; $hpc_params = array("type" => "object", "subtype" => "hpcroles"); $allRoles = elgg_get_entities($hpc_params); if (!$allRoles) { //default condition (!$allRoles) trigger_plugin_hook('action', 'load', 'homepaage_cms_action_hook', array("hpc_role_check" => true)); } else { //system_message('Total: '.count($allRoles)); //var_dump($allRoles); //system_message((string)$allRoles[0]->guid); /*foreach($allRoles as $role){ //var_dump($role); //system_message((string)$role->guid); }*/ } switch ($page_type) { case 'all': include "{$base_plugin_pages}/index.php"; break; } return true; }
/** * Encode a location into a latitude and longitude, caching the result. * * Works by triggering the 'geocode' 'location' plugin hook, and requires a geocoding module to be installed * activated in order to work. * * @param String $location The location, e.g. "London", or "24 Foobar Street, Gotham City" */ function elgg_geocode_location($location) { global $CONFIG; // Handle cases where we are passed an array (shouldn't be but can happen if location is a tag field) if (is_array($location)) { $location = implode(', ', $location); } $location = sanitise_string($location); // Look for cached version $cached_location = get_data_row("SELECT * from {$CONFIG->dbprefix}geocode_cache WHERE location='{$location}'"); if ($cached_location) { return array('lat' => $cached_location->lat, 'long' => $cached_location->long); } // Trigger geocode event if not cached $return = false; $return = 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 execute_delayed_write_query("INSERT DELAYED INTO {$CONFIG->dbprefix}geocode_cache (location, lat, `long`) VALUES ('{$location}', '{$lat}', '{$long}') ON DUPLICATE KEY UPDATE lat='{$lat}', `long`='{$long}'"); } return $return; }
/** * Get a variable from either the session, or if its not in the session attempt to get it from * an api call. */ function offsetGet($key) { if (!ElggSession::$__localcache) { ElggSession::$__localcache = array(); } if (isset($_SESSION[$key])) { return $_SESSION[$key]; } if (isset(ElggSession::$__localcache[$key])) { return ElggSession::$__localcache[$key]; } $value = null; $value = trigger_plugin_hook('session:get', $key, null, $value); ElggSession::$__localcache[$key] = $value; return ElggSession::$__localcache[$key]; }
/** * Encode a location into a latitude and longitude, caching the result. * * Works by triggering the 'geocode' 'location' plugin hook, and requires a geocoding module to be installed * activated in order to work. * * @param String $location The location, e.g. "London", or "24 Foobar Street, Gotham City" */ function elgg_geocode_location($location) { global $CONFIG; $location = sanitise_string($location); // Look for cached version $cached_location = get_data_row("SELECT * from {$CONFIG->dbprefix}geocode_cache WHERE location='{$location}'"); // Trigger geocode event $return = false; $return = trigger_plugin_hook('geocode', 'location', array('location' => $location, $return)); // If returned, cache and return value if ($return && is_array($return)) { $lat = (int) $return['lat']; $long = (int) $return['long']; // Put into cache at the end of the page since we don't really care that much execute_delayed_write_query("INSERT DELAYED INTO {$CONFIG->dbprefix}geocode_cache (lat, long) VALUES ({$lat}, {$long}) ON DUPLICATE KEY UPDATE lat={$lat} long={$long}"); } return $return; }
/** * Elgg captcha plugin * * @package ElggCaptcha * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2 * @author Curverider Ltd * @copyright Curverider Ltd 2008-2010 * @link http://elgg.com/ */ function captcha_init() { global $CONFIG; // Register page handler for captcha functionality register_page_handler('captcha', 'captcha_page_handler'); // Extend CSS elgg_extend_view('css', 'captcha/css'); // Number of background images $CONFIG->captcha_num_bg = 5; // Default length $CONFIG->captcha_length = 5; // Register a function that provides some default override actions register_plugin_hook('actionlist', 'captcha', 'captcha_actionlist_hook'); // Register actions to intercept $actions = array(); $actions = trigger_plugin_hook('actionlist', 'captcha', null, $actions); if ($actions && is_array($actions)) { foreach ($actions as $action) { register_plugin_hook("action", $action, "captcha_verify_action_hook"); } } }
} else { if (get_input('returntoreferer')) { forward($_SERVER['HTTP_REFERER']); } else { forward("pg/dashboard/"); } } } } else { $error_msg = elgg_echo('loginerror'); // figure out why the login failed if (!empty($username) && !empty($password)) { // See if it exists and is disabled $access_status = access_get_show_hidden_status(); access_show_hidden_entities(true); if (($user = get_user_by_username($username)) && !$user->validated) { // give plugins a chance to respond if (!trigger_plugin_hook('unvalidated_login_attempt', 'user', array('entity' => $user))) { // if plugins have not registered an action, the default action is to // trigger the validation event again and assume that the validation // event will display an appropriate message trigger_elgg_event('validate', 'user', $user); } } else { register_error(elgg_echo('loginerror')); } access_show_hidden_entities($access_status); } else { register_error(elgg_echo('loginerror')); } }
*/ $title = get_input('title'); $description = get_input('description'); $address = get_input('address'); $access = ACCESS_PRIVATE; //this is private and only admins can see it if ($title && $address) { $entity = new ElggObject(); $entity->subtype = "reported_content"; $entity->owner_guid = $_SESSION['user']->getGUID(); $entity->title = $title; $entity->address = $address; $entity->description = $description; $entity->access_id = $access; if ($entity->save()) { if (!trigger_plugin_hook('reportedcontent:add', $reported->type, array('entity' => $reported), true)) { $entity->delete(); register_error(elgg_echo('reportedcontent:failed')); } else { system_message(elgg_echo('reportedcontent:success')); $entity->state = "active"; } forward($address); } else { register_error(elgg_echo('reportedcontent:failed')); forward($address); } } else { register_error(elgg_echo('reportedcontent:failed')); forward($address); }
function exportAsArray($guid) { $guid = (int) $guid; // Initialise the array $to_be_serialised = array(); // Trigger a hook to $to_be_serialised = trigger_plugin_hook("export", "all", array("guid" => $guid), $to_be_serialised); // Sanity check if (!is_array($to_be_serialised) || count($to_be_serialised) == 0) { throw new ExportException(sprintf(elgg_echo('ExportException:NoSuchEntity'), $guid)); } return $to_be_serialised; }
* @package Elgg * @subpackage Core * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2 * @author Curverider Ltd * @copyright Curverider Ltd 2008-2009 * @link http://elgg.org/ */ // Load Elgg engine define('externalpage', true); require_once "../start.php"; global $CONFIG; // Get basic parameters $period = get_input('period'); if (!$period) { throw new CronException(sprintf(elgg_echo('CronException:unknownperiod'), $period)); } // Get a list of parameters $params = array(); $params['time'] = time(); foreach ($CONFIG->input as $k => $v) { $params[$k] = $v; } // Trigger hack $std_out = ""; // Data to return to $old_stdout = ""; ob_start(); $old_stdout = trigger_plugin_hook('cron', $period, $params, $old_stdout); $std_out = ob_get_clean(); // Return event echo $std_out . $old_stdout;
} // add access $access_suffix .= get_access_sql_suffix("e"); // Add access controls for ($mindex = 1; $mindex <= count($meta_array); $mindex++) { $access_suffix .= ' and ' . get_access_sql_suffix("m{$mindex}"); // Add access controls } if (empty($select)) { $select = "distinct e.*"; } // extend with hooks $join = trigger_plugin_hook("extend_join", "profile_manager_member_search", null, $join); $order = trigger_plugin_hook("extend_order", "profile_manager_member_search", null, $order); $select = trigger_plugin_hook("extend_select", "profile_manager_member_search", null, $select); $where_clause = trigger_plugin_hook("extend_where", "profile_manager_member_search", null, $where_clause); // build query $query = "from {$CONFIG->dbprefix}entities e join {$CONFIG->dbprefix}users_entity u on e.guid = u.guid {$join} where " . $where_clause . $access_suffix; // execute query and retrieve entities $count = get_data_row("SELECT count(distinct e.guid) as total " . $query); $count = $count->total; if (!empty($order)) { $order = " order by " . $order; } $query = "SELECT " . $select . " " . $query . " " . $group_by . $order . " limit {$offset},{$limit}"; $entities = get_data($query, "entity_row_to_elggstar"); // present it echo "<div class='contentWrapper'>"; echo "<h3 class='settings'>" . elgg_echo("profile_manager:members:searchresults:title") . "</h3>"; if ($count > 0) { $nav = elgg_view('profile_manager/members/pagination', array('function_name' => "navigate_members_search", 'offset' => $offset, 'count' => $count, 'limit' => $limit));
} else { if (empty($objecttype)) { $objecttype = 'object'; } $itemtitle = 'item:' . $objecttype; if (!empty($subtype)) { $itemtitle .= ':' . $subtype; } $itemtitle = elgg_echo($itemtitle); $title = sprintf(elgg_echo('advancedsearchtitle'), $itemtitle, $tag); } global $CONFIG; $tagSearch = false; if (strpos(current_page_url(), $CONFIG->wwwroot . 'tag') > -1 || strpos(current_page_url(), $CONFIG->wwwroot . 'search/?tag') > -1) { $tagSearch = true; } if (!empty($tag)) { $body = ""; $body .= elgg_view_title($title); // elgg_view_title(sprintf(elgg_echo('searchtitle'),$tag)); //the custom search doesn't work with tag searching if (!$tagSearch) { $body .= trigger_plugin_hook('search', '', $tag, ""); } $body .= elgg_view('search/startblurb', array('tag' => $tag)); $body .= list_entities_from_metadata($md_type, $tag, $objecttype, $subtype, $owner_guid_array, 10, false, false); $body = elgg_view_layout('two_column_left_sidebar', '', $body); } if ($tagSearch) { page_draw($title, $body); }
<?php $email = get_input('email'); $user = get_user_by_email($email); if (is_array($user)) { $user = $user[0]; } if ($user) { if ($user->validated) { if (send_new_password_request($user->guid)) { system_message(elgg_echo('user:password:resetreq:success')); } else { register_error(elgg_echo('user:password:resetreq:fail')); } } else { if (!trigger_plugin_hook('unvalidated_requestnewpassword', 'user', array('entity' => $user))) { // if plugins have not registered an action, the default action is to // trigger the validation event again and assume that the validation // event will display an appropriate message trigger_elgg_event('validate', 'user', $user); } } } else { register_error(sprintf(elgg_echo('user:email:notfound'), $email)); } forward();
<?php /** * Aggregate action for saving settings * * @package Elgg * @subpackage Core * @link http://elgg.org/ */ global $CONFIG; gatekeeper(); trigger_plugin_hook('usersettings:save', 'user'); forward($_SERVER['HTTP_REFERER']);
case "pop": $filter_content = list_entities_by_relationship_count('friend', true, '', '', 0, 10, false); break; case "active": $filter_content = elgg_view("members/online"); break; // search based on name // search based on name case "search": set_context('search'); $filter_content = list_user_search($tag); break; // search based on tags // search based on tags case "search_tags": $filter_content = trigger_plugin_hook('search', '', $tag, ""); $filter_content .= list_entities_from_metadata("", $tag, "user", "", "", 10, false, false); break; case "newest": case 'default': $filter_content = elgg_list_entities(array('type' => 'user', 'offset' => $offset, 'full_view' => FALSE)); break; } // create the members navigation/filtering $members = get_number_users(); $members_nav = elgg_view("members/members_sort_menu", array("count" => $members, "filter" => $filter)); $content = $members_nav . $filter_content; // title $main_content = elgg_view_title(elgg_echo("members:members")); $main_content .= elgg_view('page_elements/contentwrapper', array('body' => $content, 'subclass' => 'members')); $body = elgg_view_layout("sidebar_boxes", $sidebar, $main_content);
/** * Set a setting for a plugin. * * @param string $name The name - note, can't be "title". * @param mixed $value The value. * @param string $plugin_name Optional plugin name, if not specified then it is detected from where you are calling from. */ function set_plugin_setting($name, $value, $plugin_name = "") { if (!$plugin_name) { $plugin_name = get_plugin_name(); } $plugin = find_plugin_settings($plugin_name); if (!$plugin) { $plugin = new ElggPlugin(); } if ($name != 'title') { // Hook to validate setting $value = trigger_plugin_hook('plugin:setting', 'plugin', array('plugin' => $plugin_name, 'name' => $name, 'value' => $value), $value); $plugin->title = $plugin_name; $plugin->access_id = ACCESS_PUBLIC; $plugin->save(); $plugin->{$name} = $value; return $plugin->getGUID(); } return false; }
/** * Elgg index page for web-based applications * * @package Elgg * @subpackage Core * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2 * @author Curverider Ltd * @copyright Curverider Ltd 2008-2009 * @link http://elgg.org/ */ /** * Start the Elgg engine */ define('externalpage', true); require_once dirname(__FILE__) . "/engine/start.php"; if (!trigger_plugin_hook('index', 'system', null, false)) { /** * Check to see if user is logged in, if not display login form **/ if (isloggedin()) { forward('pg/dashboard/'); } //Load the front page global $CONFIG; $title = elgg_view_title(elgg_echo('content:latest')); set_context('search'); $content = list_registered_entities(0, 10, true, false, array('object', 'group')); set_context('main'); global $autofeed; $autofeed = false; $content = elgg_view_layout('two_column_left_sidebar', '', $title . $content, elgg_view("account/forms/login"));
/** * Listen to /livesearc for special mentions search * * @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 array */ function theme_haarlem_intranet_livesearch_route_handler($hook, $type, $return_value, $params) { $query = get_input('q', get_input('term')); if (empty($query)) { return $return_value; } $match_on = get_input('match_on'); if (empty($match_on)) { return $return_value; } if (is_array($match_on) && count($match_on) > 1) { return $return_value; } if (is_array($match_on)) { $match_on = $match_on[0]; } $overrule_cases = array('mentions', 'member_of_site'); if (!in_array($match_on, $overrule_cases)) { return $return_value; } // backup search advanced mulitsite search setting $mulitsite = elgg_extract('search_advanced:multisite', $_SESSION); $_SESSION['search_advanced:multisite'] = false; $params = array('type' => 'user', 'limit' => 10, 'query' => sanitise_string($query)); $users = trigger_plugin_hook('search', 'user', $params, array()); if (empty($users) || !is_array($users)) { header("Content-Type: application/json"); echo json_encode(array()); return false; } $count = elgg_extract('count', $users); if (empty($count)) { header("Content-Type: application/json"); echo json_encode(array()); return false; } $users = elgg_extract('entities', $users); $results = array(); foreach ($users as $user) { $output = elgg_view_list_item($user, array('use_hover' => false, 'class' => 'elgg-autocomplete-item')); $icon = elgg_view_entity_icon($user, 'tiny', array('use_hover' => false)); $result = array('type' => 'user', 'name' => $user->name, 'desc' => $user->username, 'guid' => $user->guid, 'label' => $output, 'value' => $user->username, 'icon' => $icon, 'url' => $user->getURL()); $results[$user->name . rand(1, 100)] = $result; } ksort($results); header("Content-Type: application/json"); echo json_encode(array_values($results)); // reset search advanced mulitsite search setting $_SESSION['search_advanced:multisite'] = $mulitsite; return false; }
/** * Get the icon for an entity * * @param ElggEntity $entity The entity (passed an entity rather than a guid to handle non-created entities) * @param string $size */ function get_entity_icon_url(ElggEntity $entity, $size = 'medium') { global $CONFIG; $size = sanitise_string($size); switch (strtolower($size)) { case 'master': $size = 'master'; break; case 'large': $size = 'large'; break; case 'topbar': $size = 'topbar'; break; case 'tiny': $size = 'tiny'; break; case 'small': $size = 'small'; break; case 'medium': default: $size = 'medium'; } $url = false; $viewtype = elgg_get_viewtype(); // Step one, see if anyone knows how to render this in the current view $url = trigger_plugin_hook('entity:icon:url', $entity->getType(), array('entity' => $entity, 'viewtype' => $viewtype, 'size' => $size), $url); // Fail, so use default if (!$url) { $type = $entity->getType(); $subtype = $entity->getSubtype(); if (!empty($subtype)) { $overrideurl = elgg_view("icon/{$type}/{$subtype}/{$size}", array('entity' => $entity)); if (!empty($overrideurl)) { return $overrideurl; } } $overrideurl = elgg_view("icon/{$type}/default/{$size}", array('entity' => $entity)); if (!empty($overrideurl)) { return $overrideurl; } $url = $CONFIG->url . "_graphics/icons/default/{$size}.png"; } return $url; }
/** * Automatically triggered notification on 'create' events that looks at registered * objects and attempts to send notifications to anybody who's interested * * @see register_notification_object */ function object_notifications($event, $object_type, $object) { // We only want to trigger notification events for ElggEntities if ($object instanceof ElggEntity) { // Get config data global $CONFIG, $SESSION, $NOTIFICATION_HANDLERS; $hookresult = trigger_plugin_hook('object:notifications', $object_type, array('event' => $event, 'object_type' => $object_type, 'object' => $object), false); if ($hookresult === true) { return true; } // Have we registered notifications for this type of entity? $object_type = $object->getType(); if (empty($object_type)) { $object_type = '__BLANK__'; } $object_subtype = $object->getSubtype(); if (empty($object_subtype)) { $object_subtype = '__BLANK__'; } if (isset($CONFIG->register_objects[$object_type][$object_subtype])) { $descr = $CONFIG->register_objects[$object_type][$object_subtype]; $string = $descr . ": " . $object->getURL(); // Get users interested in content from this person and notify them // (Person defined by container_guid so we can also subscribe to groups if we want) foreach ($NOTIFICATION_HANDLERS as $method => $foo) { $interested_users = elgg_get_entities_from_relationship(array('relationship' => 'notify' . $method, 'relationship_guid' => $object->container_guid, 'inverse_relationship' => TRUE, 'types' => 'user', 'limit' => 99999)); if ($interested_users && is_array($interested_users)) { foreach ($interested_users as $user) { if ($user instanceof ElggUser && !$user->isBanned()) { if ($user->guid != $SESSION['user']->guid && has_access_to_entity($object, $user) && $object->access_id != ACCESS_PRIVATE) { $methodstring = trigger_plugin_hook('notify:entity:message', $object->getType(), array('entity' => $object, 'to_entity' => $user, 'method' => $method), $string); if (empty($methodstring) && $methodstring !== false) { $methodstring = $string; } if ($methodstring !== false) { notify_user($user->guid, $object->container_guid, $descr, $methodstring, NULL, array($method)); } } } } } } } } }
/** * Simple validation of a email. * * @param string $address * @throws RegistrationException on invalid * @return bool */ function validate_email_address($address) { if (!is_email_address($address)) { throw new RegistrationException(elgg_echo('registration:notemail')); } // Got here, so lets try a hook (defaulting to ok) $result = true; return trigger_plugin_hook('registeruser:validate:email', 'all', array('email' => $address), $result); }
/** * Count the number of comments attached to an entity * * @param ElggEntity $entity * @return int Number of comments */ function elgg_count_comments($entity) { if ($commentno = trigger_plugin_hook('comments:count', $entity->getType(), array('entity' => $entity), false)) { return $commentno; } else { return count_annotations($entity->getGUID(), "", "", "generic_comment"); } }
/** * Validate an action token, returning true if valid and false if not * * @return unknown */ function validate_action_token($visibleerrors = true) { $token = get_input('__elgg_token'); $ts = get_input('__elgg_ts'); $session_id = session_id(); if ($token && $ts && $session_id) { // generate token, check with input and forward if invalid $generated_token = generate_action_token($ts); // Validate token if (strcmp($token, $generated_token) == 0) { $hour = 60 * 60; $now = time(); // Validate time to ensure its not crazy if ($ts > $now - $hour && $ts < $now + $hour) { $returnval = true; // We have already got this far, so unless anything else says something to the contry we assume we're ok $returnval = trigger_plugin_hook('action_gatekeeper:permissions:check', 'all', array('token' => $token, 'time' => $ts), $returnval); if ($returnval) { return true; } else { if ($visibleerrors) { register_error(elgg_echo('actiongatekeeper:pluginprevents')); } } } else { if ($visibleerrors) { register_error(elgg_echo('actiongatekeeper:timeerror')); } } } else { if ($visibleerrors) { register_error(elgg_echo('actiongatekeeper:tokeninvalid')); } } } else { if ($visibleerrors) { register_error(elgg_echo('actiongatekeeper:missingfields')); } } return false; }
/** * Start the Elgg engine */ require_once "../../engine/start.php"; global $CONFIG; // Register the error handler error_reporting(E_ALL); set_error_handler('__php_api_error_handler'); // Register a default exception handler set_exception_handler('__php_api_exception_handler'); // Check to see if the api is available if (isset($CONFIG->disable_api) && $CONFIG->disable_api == true) { throw new SecurityException(elgg_echo('SecurityException:APIAccessDenied')); } // plugins should return true to control what API and user authentication handlers are registered if (trigger_plugin_hook('rest', 'init', null, false) == false) { // check session - this usually means a REST call from a web browser register_pam_handler('pam_auth_session'); // user token can also be used for user authentication register_pam_handler('pam_auth_usertoken'); // simple API key check register_pam_handler('api_auth_key', "sufficient", "api"); // hmac register_pam_handler('api_auth_hmac', "sufficient", "api"); } // Get parameter variables $method = get_input('method'); $result = null; // this will throw an exception if authentication fails authenticate_method($method); $result = execute_method($method);
</li> </ul> </div> <div id="tidypics_image_wrapper"> <?php // this code controls whether the photo is a hyperlink or not and what it links to if (get_plugin_setting('download_link', 'tidypics') != "disabled") { // admin allows downloads so default to inline download link $image_html = "<a href=\"{$vars['url']}pg/photos/download/{$image_guid}/inline/\" title=\"{$title}\" >"; $image_html .= "<img id=\"tidypics_image\" src=\"{$vars['url']}pg/photos/thumbnail/{$image_guid}/large/\" alt=\"{$title}\" />"; $image_html .= "</a>"; } else { $image_html = "<img id=\"tidypics_image\" src=\"{$vars['url']}pg/photos/thumbnail/{$image_guid}/large/\" alt=\"{$title}\" />"; } // does any plugin want to override the link $image_html = trigger_plugin_hook('tp_thumbnail_link', 'image', array('image' => $image), $image_html); echo $image_html; ?> <div class="clearfloat"></div> </div> <?php // image menu (start tagging, download, etc.) echo '<div id="tidypics_controls"><ul>'; echo elgg_view('tidypics/image_menu', array('image_guid' => $image_guid, 'viewer' => $viewer, 'owner' => $owner, 'anytags' => $image->isPhotoTagged(), 'album' => $album)); echo '</ul></div>'; // tagging code - photo tags on images, photo tag listing and hidden divs used in tagging if (get_plugin_setting('tagging', 'tidypics') != "disabled") { echo elgg_view('tidypics/tagging', array('image' => $image, 'viewer' => $viewer, 'owner' => $owner)); } if (get_plugin_setting('exif', 'tidypics') == "enabled") { echo elgg_view('tidypics/exif', array('guid' => $image_guid));
/** * Removes a user from an access collection * * @param int $user_guid The user GUID * @param int $collection_id The access collection ID * @return true|false Depending on success */ function remove_user_from_access_collection($user_guid, $collection_id) { $collection_id = (int) $collection_id; $user_guid = (int) $user_guid; $collections = get_write_access_array(); if (!($collection = get_access_collection($collection_id))) { return false; } if ((array_key_exists($collection_id, $collections) || $collection->owner_guid == 0) && ($user = get_user($user_guid))) { global $CONFIG; $params = array('collection_id' => $collection_id, 'user_guid' => $user_guid); if (!trigger_plugin_hook('access:collections:remove_user', 'collection', $params, true)) { return false; } delete_data("delete from {$CONFIG->dbprefix}access_collection_membership where access_collection_id = {$collection_id} and user_guid = {$user_guid}"); return true; } return false; }
/** * Filter tags from a given string based on registered hooks. * @param $var * @return mixed The filtered result */ function filter_tags($var) { return trigger_plugin_hook('validate', 'input', null, $var); }
/** * This function loads a set of default fields into the profile, then triggers a hook letting other plugins to edit * add and delete fields. * * Note: This is a secondary system:init call and is run at a super low priority to guarantee that it is called after all * other plugins have initialised. */ function groups_fields_setup() { global $CONFIG; $profile_defaults = array('name' => 'text', 'description' => 'longtext', 'briefdescription' => 'text', 'interests' => 'tags', 'website' => 'url'); $CONFIG->group = trigger_plugin_hook('profile:fields', 'group', NULL, $profile_defaults); // register any tag metadata names foreach ($CONFIG->group as $name => $type) { if ($type == 'tags') { elgg_register_tag_metadata_name($name); // register a tag name translation add_translation(get_current_language(), array("tag_names:{$name}" => elgg_echo("groups:{$name}"))); } } }