本文整理汇总了PHP中elgg_trigger_plugin_hook函数的典型用法代码示例。如果您正苦于以下问题:PHP elgg_trigger_plugin_hook函数的具体用法?PHP elgg_trigger_plugin_hook怎么用?PHP elgg_trigger_plugin_hook使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了elgg_trigger_plugin_hook函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: site_search
/**
* 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;
}
示例2: user_friends_can_view_friends
/**
* 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);
}
示例3: embed_page_handler
/**
* 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;
}
示例4: garbagecollector_cron
/**
* 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');
}
示例5: process
/**
* @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;
}
示例6: elgg_geocode_location
/**
* 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;
}
示例7: __construct
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;
}
示例8: analytics_track_event
/**
* 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;
}
示例9: widget_manager_widget_url_handler
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;
}
示例10: twitter_api_tweet
/**
* 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;
}
示例11: elggx_fivestar_vote
/**
* 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;
}
示例12: handleUploads
/**
* 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;
}
示例13: route
/**
* 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();
}
示例14: badges_userpoints
/**
* 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;
}
示例15: crontrigger_trigger
function crontrigger_trigger($period)
{
$now = time();
$params = array();
$params['time'] = $now;
elgg_trigger_plugin_hook('cron', $period, $params, "");
}