本文整理汇总了PHP中elgg_trigger_event函数的典型用法代码示例。如果您正苦于以下问题:PHP elgg_trigger_event函数的具体用法?PHP elgg_trigger_event怎么用?PHP elgg_trigger_event使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了elgg_trigger_event函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create_object_entity
/**
* Create or update the extras table for a given object.
* Call create_entity first.
*
* @param int $guid The guid of the entity you're creating (as obtained by create_entity)
* @param string $title The title of the object
* @param string $description The object's description
*
* @return bool
*/
function create_object_entity($guid, $title, $description)
{
global $CONFIG;
$guid = (int) $guid;
$title = sanitise_string($title);
$description = sanitise_string($description);
$row = get_entity_as_row($guid);
if ($row) {
// Core entities row exists and we have access to it
$query = "SELECT guid from {$CONFIG->dbprefix}objects_entity where guid = {$guid}";
if ($exists = get_data_row($query)) {
$query = "UPDATE {$CONFIG->dbprefix}objects_entity\n\t\t\t\tset title='{$title}', description='{$description}' where guid={$guid}";
$result = update_data($query);
if ($result != false) {
// Update succeeded, continue
$entity = get_entity($guid);
elgg_trigger_event('update', $entity->type, $entity);
return $guid;
}
} else {
// Update failed, attempt an insert.
$query = "INSERT into {$CONFIG->dbprefix}objects_entity\n\t\t\t\t(guid, title, description) values ({$guid}, '{$title}','{$description}')";
$result = insert_data($query);
if ($result !== false) {
$entity = get_entity($guid);
if (elgg_trigger_event('create', $entity->type, $entity)) {
return $guid;
} else {
$entity->delete();
}
}
}
}
return false;
}
示例2: publishBlogs
/**
* Publish blogs based on advanced publication settings
*
* @param int $time the timestamp the entity was published
*
* @return void
*/
protected static function publishBlogs($time)
{
$dbprefix = elgg_get_config('dbprefix');
$publication_id = elgg_get_metastring_id('publication_date');
$publish_options = ['type' => 'object', 'subtype' => 'blog', 'limit' => false, 'joins' => ["JOIN {$dbprefix}metadata mdtime ON e.guid = mdtime.entity_guid", "JOIN {$dbprefix}metastrings mstime ON mdtime.value_id = mstime.id"], 'metadata_name_value_pairs' => [['name' => 'status', 'value' => 'draft']], 'wheres' => ["((mdtime.name_id = {$publication_id}) AND (DATE(mstime.string) = DATE(NOW())))"]];
// get unpublished blogs that need to be published
$entities = new \ElggBatch('elgg_get_entities_from_metadata', $publish_options);
foreach ($entities as $entity) {
// add river item
elgg_create_river_item(['view' => 'river/object/blog/create', 'action_type' => 'create', 'subject_guid' => $entity->getOwnerGUID(), 'object_guid' => $entity->getGUID()]);
// set correct time created
$entity->time_created = $time;
// publish blog
$entity->status = 'published';
// revert access
$entity->access_id = $entity->future_access;
unset($entity->future_access);
// send notifications when post published
elgg_trigger_event('publish', 'object', $entity);
// notify owner
notify_user($entity->getOwnerGUID(), $entity->site_guid, elgg_echo('blog_tools:notify:publish:subject'), elgg_echo('blog_tools:notify:publish:message', [$entity->title, $entity->getURL()]));
// save everything
$entity->save();
}
}
示例3: addTaggedWirePost
function addTaggedWirePost($hook, $type, $params)
{
global $CONFIG;
$id = insert_data("insert into {$CONFIG->dbprefix}river " . " set type = '" . $params['type'] . "', " . " subtype = '" . $params['subtype'] . "', " . " action_type = '" . $params['action_type'] . "', " . " access_id = '" . $params['access_id'] . "', " . " view = '" . $params['view'] . "', " . " subject_guid = '" . $params['subject_guid'] . "', " . " object_guid = '" . $params['object_guid'] . "', " . " annotation_id = '" . $params['annotation_id'] . "', " . " posted = '" . $params['posted'] . "';");
$tags = "";
if (isset($_SESSION['role'])) {
switch ($_SESSION['role']) {
case "learner":
$tags = "Learner-Apprenant";
break;
case "instructor":
$tags = "Instructor-Instructeur";
break;
case "developer":
$tags = "Developer-Développeur";
break;
case "trainingmgr":
$tags = "trainingmgr";
break;
}
$roleTags = $_SESSION['role'];
}
if ($roleTags) {
$metaID = create_metadata($params['object_guid'], "tags", "{$tags}", "text", elgg_get_logged_in_user_guid(), 2, true);
}
if ($id) {
update_entity_last_action($object_guid, $posted);
$river_items = elgg_get_river(array('id' => $id));
if ($river_items) {
elgg_trigger_event('created', 'river', $river_items[0]);
}
}
return false;
}
示例4: enqueue
/**
* Enqueue the mail for delivery
*
* @return bool
*/
public function enqueue()
{
if (!$this->save()) {
return false;
}
elgg_trigger_event('enqueue', 'object', $this);
return true;
}
示例5: add_to_river
/**
* Adds an item to the river.
*
* @param string $view The view that will handle the river item (must exist)
* @param string $action_type An arbitrary string to define the action (eg 'comment', 'create')
* @param int $subject_guid The GUID of the entity doing the action
* @param int $object_guid The GUID of the entity being acted upon
* @param int $access_id The access ID of the river item (default: same as the object)
* @param int $posted The UNIX epoch timestamp of the river item (default: now)
* @param int $annotation_id The annotation ID associated with this river entry
*
* @return int/bool River ID or false on failure
*/
function add_to_river($view, $action_type, $subject_guid, $object_guid, $access_id = "", $posted = 0, $annotation_id = 0)
{
global $CONFIG;
// use default viewtype for when called from web services api
if (!elgg_view_exists($view, 'default')) {
return false;
}
if (!($subject = get_entity($subject_guid))) {
return false;
}
if (!($object = get_entity($object_guid))) {
return false;
}
if (empty($action_type)) {
return false;
}
if ($posted == 0) {
$posted = time();
}
if ($access_id === "") {
$access_id = $object->access_id;
}
$type = $object->getType();
$subtype = $object->getSubtype();
$view = sanitise_string($view);
$action_type = sanitise_string($action_type);
$subject_guid = sanitise_int($subject_guid);
$object_guid = sanitise_int($object_guid);
$access_id = sanitise_int($access_id);
$posted = sanitise_int($posted);
$annotation_id = sanitise_int($annotation_id);
$values = array('type' => $type, 'subtype' => $subtype, 'action_type' => $action_type, 'access_id' => $access_id, 'view' => $view, 'subject_guid' => $subject_guid, 'object_guid' => $object_guid, 'annotation_id' => $annotation_id, 'posted' => $posted);
// return false to stop insert
$values = elgg_trigger_plugin_hook('creating', 'river', null, $values);
if ($values == false) {
// inserting did not fail - it was just prevented
return true;
}
extract($values);
// Attempt to save river item; return success status
$id = insert_data("insert into {$CONFIG->dbprefix}river " . " set type = '{$type}', " . " subtype = '{$subtype}', " . " action_type = '{$action_type}', " . " access_id = {$access_id}, " . " view = '{$view}', " . " subject_guid = {$subject_guid}, " . " object_guid = {$object_guid}, " . " annotation_id = {$annotation_id}, " . " posted = {$posted}");
// update the entities which had the action carried out on it
// @todo shouldn't this be down elsewhere? Like when an annotation is saved?
if ($id) {
update_entity_last_action($object_guid, $posted);
$river_items = elgg_get_river(array('id' => $id));
if ($river_items) {
elgg_trigger_event('created', 'river', $river_items[0]);
}
return $id;
} else {
return false;
}
}
示例6: markAsCorrect
/**
* Mark an answer as the correct answer for this question
*
* @return void
*/
public function markAsCorrect()
{
// first set the mark
$this->correct_answer = true;
// trigger event for notifications
elgg_trigger_event('correct', 'object', $this);
// depending of the plugin settings, we also need to close the question
if (questions_close_on_marked_answer()) {
$question = $this->getContainerEntity();
$question->close();
}
}
示例7: widget_manager_init
function widget_manager_init()
{
// check valid WidgetManagerWidget class
if (get_subtype_class("object", "widget") == "ElggWidget") {
update_subtype("object", "widget", "WidgetManagerWidget");
}
elgg_trigger_event("widgets_init", "widget_manager");
if (elgg_is_active_plugin("groups") && elgg_get_plugin_setting("group_enable", "widget_manager") == "yes") {
// add the widget manager tool option
$group_option_enabled = false;
if (elgg_get_plugin_setting("group_option_default_enabled", "widget_manager") == "yes") {
$group_option_enabled = true;
}
if (elgg_get_plugin_setting("group_option_admin_only", "widget_manager") != "yes") {
// add the tool option for group admins
add_group_tool_option('widget_manager', elgg_echo('widget_manager:groups:enable_widget_manager'), $group_option_enabled);
} elseif (elgg_is_admin_logged_in()) {
add_group_tool_option('widget_manager', elgg_echo('widget_manager:groups:enable_widget_manager'), $group_option_enabled);
} elseif ($group_option_enabled) {
// register event to make sure newly created groups have the group option enabled
elgg_register_event_handler("create", "group", "widget_manager_create_group_event_handler");
elgg_register_plugin_hook_handler('get_list', 'default_widgets', 'widget_manager_group_widgets_default_list');
}
}
// extend CSS
elgg_extend_view("css/elgg", "widget_manager/css/global");
elgg_extend_view("css/admin", "widget_manager/css/global");
elgg_extend_view("js/elgg", "widget_manager/js/site");
elgg_extend_view("js/admin", "widget_manager/js/admin");
// register a widget title url handler
elgg_register_entity_url_handler("object", "widget", "widget_manager_widget_url_handler");
// multi dashboard support
add_subtype("object", MultiDashboard::SUBTYPE, "MultiDashboard");
if (elgg_is_logged_in() && widget_manager_multi_dashboard_enabled()) {
elgg_register_page_handler("multi_dashboard", "widget_manager_multi_dashboard_page_handler");
$options = array("type" => "object", "subtype" => MultiDashboard::SUBTYPE, "owner_guid" => elgg_get_logged_in_user_guid(), "count" => true);
$tab_count = elgg_get_entities($options);
if ($tab_count < MULTI_DASHBOARD_MAX_TABS) {
elgg_register_menu_item("extras", array("name" => "multi_dashboard", "text" => elgg_view_icon("home"), "href" => "multi_dashboard/edit/?internal_url=" . urlencode(current_page_url()), "title" => elgg_echo("widget_manager:multi_dashboard:extras"), "rel" => "nofollow", "id" => "widget-manager-multi_dashboard-extras"));
}
elgg_extend_view("page/elements/sidebar", "widget_manager/multi_dashboard/sidebar", 400);
elgg_register_event_handler("create", "object", "widget_manager_create_object_handler");
elgg_register_plugin_hook_handler("route", "dashboard", "widget_manager_dashboard_route_handler");
elgg_register_plugin_hook_handler("action", "widgets/add", "widget_manager_widgets_add_action_handler");
elgg_register_action("multi_dashboard/edit", dirname(__FILE__) . "/actions/multi_dashboard/edit.php");
elgg_register_action("multi_dashboard/delete", dirname(__FILE__) . "/actions/multi_dashboard/delete.php");
elgg_register_action("multi_dashboard/drop", dirname(__FILE__) . "/actions/multi_dashboard/drop.php");
elgg_register_action("multi_dashboard/reorder", dirname(__FILE__) . "/actions/multi_dashboard/reorder.php");
}
}
示例8: save
/**
* Save an album
*
* @return bool
*/
public function save()
{
if (!isset($this->new_album)) {
$this->new_album = true;
}
if (!isset($this->last_notified)) {
$this->last_notified = 0;
}
if (!parent::save()) {
return false;
}
mkdir(tp_get_img_dir() . $this->guid, 0755, true);
elgg_trigger_event('create', 'album', $this);
return true;
}
示例9: daily
/**
* Publish blogs based on advanced publication options
*
* @param string $hook 'cron'
* @param string $type 'daily'
* @param string $return_value optional stdout text
* @param array $params supplied params
*
* @return void
*/
public static function daily($hook, $type, $return_value, $params)
{
// only do if this is configured
if (!blog_tools_use_advanced_publication_options()) {
return $return_value;
}
$dbprefix = elgg_get_config("dbprefix");
$publication_id = elgg_get_metastring_id("publication_date");
$expiration_id = elgg_get_metastring_id("expiration_date");
$time = elgg_extract("time", $params, time());
$publish_options = array("type" => "object", "subtype" => "blog", "limit" => false, "joins" => array("JOIN " . $dbprefix . "metadata mdtime ON e.guid = mdtime.entity_guid", "JOIN " . $dbprefix . "metastrings mstime ON mdtime.value_id = mstime.id"), "metadata_name_value_pairs" => array(array("name" => "status", "value" => "draft")), "wheres" => array("((mdtime.name_id = " . $publication_id . ") AND (DATE(mstime.string) = DATE(NOW())))"));
$unpublish_options = array("type" => "object", "subtype" => "blog", "limit" => false, "joins" => array("JOIN " . $dbprefix . "metadata mdtime ON e.guid = mdtime.entity_guid", "JOIN " . $dbprefix . "metastrings mstime ON mdtime.value_id = mstime.id"), "metadata_name_values_pairs" => array(array("name" => "status", "value" => "published")), "wheres" => array("((mdtime.name_id = " . $expiration_id . ") AND (DATE(mstime.string) = DATE(NOW())))"));
// ignore access
$ia = elgg_set_ignore_access(true);
// get unpublished blogs that need to be published
$entities = new \ElggBatch("elgg_get_entities_from_metadata", $publish_options);
foreach ($entities as $entity) {
// add river item
elgg_create_river_item(array("view" => "river/object/blog/create", "action_type" => "create", "subject_guid" => $entity->getOwnerGUID(), "object_guid" => $entity->getGUID()));
// set correct time created
$entity->time_created = $time;
// publish blog
$entity->status = "published";
// revert access
$entity->access_id = $entity->future_access;
unset($entity->future_access);
// send notifications when post published
elgg_trigger_event('publish', 'object', $entity);
// notify owner
notify_user($entity->getOwnerGUID(), $entity->site_guid, elgg_echo("blog_tools:notify:publish:subject"), elgg_echo("blog_tools:notify:publish:message", array($entity->title, $entity->getURL())));
// save everything
$entity->save();
}
// get published blogs that need to be unpublished
$entities = new \ElggBatch("elgg_get_entities_from_metadata", $unpublish_options);
foreach ($entities as $entity) {
// remove river item
elgg_delete_river(array("object_guid" => $entity->getGUID(), "action_type" => "create"));
// unpublish blog
$entity->status = "draft";
// notify owner
notify_user($entity->getOwnerGUID(), $entity->site_guid, elgg_echo("blog_tools:notify:expire:subject"), elgg_echo("blog_tools:notify:expire:message", array($entity->title, $entity->getURL())));
// save everything
$entity->save();
}
// reset access
elgg_set_ignore_access($ia);
}
示例10: create_site_entity
/**
* Create or update the entities table for a given site.
* Call create_entity first.
*
* @param int $guid Site GUID
* @param string $name Site name
* @param string $description Site Description
* @param string $url URL of the site
*
* @return bool
*/
function create_site_entity($guid, $name, $description, $url)
{
global $CONFIG;
$guid = (int) $guid;
$name = sanitise_string($name);
$description = sanitise_string($description);
$url = sanitise_string($url);
$row = get_entity_as_row($guid);
if ($row) {
// Exists and you have access to it
$query = "SELECT guid from {$CONFIG->dbprefix}sites_entity where guid = {$guid}";
if ($exists = get_data_row($query)) {
$query = "UPDATE {$CONFIG->dbprefix}sites_entity\n\t\t\t\tset name='{$name}', description='{$description}', url='{$url}' where guid={$guid}";
$result = update_data($query);
if ($result != false) {
// Update succeeded, continue
$entity = get_entity($guid);
if (elgg_trigger_event('update', $entity->type, $entity)) {
return $guid;
} else {
$entity->delete();
//delete_entity($guid);
}
}
} else {
// Update failed, attempt an insert.
$query = "INSERT into {$CONFIG->dbprefix}sites_entity\n\t\t\t\t(guid, name, description, url) values ({$guid}, '{$name}', '{$description}', '{$url}')";
$result = insert_data($query);
if ($result !== false) {
$entity = get_entity($guid);
if (elgg_trigger_event('create', $entity->type, $entity)) {
return $guid;
} else {
$entity->delete();
//delete_entity($guid);
}
}
}
}
return false;
}
示例11: group_tools_delete_annotations
/**
* Custom annotations delete function because logged out users can't delete annotations
*
* @param array $annotations annotations to delete
*
* @return void
*/
function group_tools_delete_annotations($annotations)
{
if (!empty($annotations) && is_array($annotations)) {
$dbprefix = elgg_get_config("dbprefix");
foreach ($annotations as $annotation) {
if (elgg_trigger_event("delete", "annotation", $annotation)) {
delete_data("DELETE from {$dbprefix}annotations where id=" . $annotation->id);
}
}
}
}
示例12: update_metadata
/**
* Update a specific piece of metadata.
*
* @param int $id ID of the metadata to update
* @param string $name Metadata name
* @param string $value Metadata value
* @param string $value_type Value type
* @param int $owner_guid Owner guid
* @param int $access_id Access ID
*
* @return bool
*/
function update_metadata($id, $name, $value, $value_type, $owner_guid, $access_id)
{
global $CONFIG;
$id = (int) $id;
if (!($md = elgg_get_metadata_from_id($id))) {
return false;
}
if (!$md->canEdit()) {
return false;
}
// If memcached then we invalidate the cache for this entry
static $metabyname_memcache;
if (!$metabyname_memcache && is_memcache_available()) {
$metabyname_memcache = new ElggMemcache('metabyname_memcache');
}
if ($metabyname_memcache) {
// @todo fix memcache (name_id is not a property of ElggMetadata)
$metabyname_memcache->delete("{$md->entity_guid}:{$md->name_id}");
}
$value_type = detect_extender_valuetype($value, sanitise_string(trim($value_type)));
$owner_guid = (int) $owner_guid;
if ($owner_guid == 0) {
$owner_guid = elgg_get_logged_in_user_guid();
}
$access_id = (int) $access_id;
// Support boolean types (as integers)
if (is_bool($value)) {
$value = (int) $value;
}
$value_id = elgg_get_metastring_id($value);
if (!$value_id) {
return false;
}
$name_id = elgg_get_metastring_id($name);
if (!$name_id) {
return false;
}
// If ok then add it
$query = "UPDATE {$CONFIG->dbprefix}metadata" . " set name_id='{$name_id}', value_id='{$value_id}', value_type='{$value_type}', access_id={$access_id}," . " owner_guid={$owner_guid} where id={$id}";
$result = update_data($query);
if ($result !== false) {
_elgg_get_metadata_cache()->save($md->entity_guid, $name, $value);
// @todo this event tells you the metadata has been updated, but does not
// let you do anything about it. What is needed is a plugin hook before
// the update that passes old and new values.
$obj = elgg_get_metadata_from_id($id);
elgg_trigger_event('update', 'metadata', $obj);
}
return $result;
}
示例13: logout
/**
* Log the current user out
*
* @return bool
*/
function logout()
{
$session = _elgg_services()->session;
$user = $session->getLoggedInUser();
if (!$user) {
return false;
}
// plugins can prevent a logout
if (!elgg_trigger_event('logout', 'user', $user)) {
return false;
}
// remove remember cookie
if (isset($_COOKIE['elggperm'])) {
_elgg_delete_remember_me_cookie(md5($_COOKIE['elggperm']));
// tell browser to delete cookie
$cookie = new ElggCookie("elggperm");
$cookie->setExpiresTime("-30 days");
$cookie->domain = "/";
elgg_set_cookie($cookie);
}
// pass along any messages into new session
$old_msg = $session->get('msg');
$session->invalidate();
$session->set('msg', $old_msg);
return true;
}
示例14: update_annotation
/**
* Update an annotation.
*
* @param int $annotation_id Annotation ID
* @param string $name Name of annotation
* @param string $value Value of annotation
* @param string $value_type Type of value
* @param int $owner_guid Owner of annotation
* @param int $access_id Access level of annotation
*
* @return bool
*/
function update_annotation($annotation_id, $name, $value, $value_type, $owner_guid, $access_id)
{
global $CONFIG;
$annotation_id = (int) $annotation_id;
$annotation = elgg_get_annotation_from_id($annotation_id);
if (!$annotation) {
return false;
}
if (!$annotation->canEdit()) {
return false;
}
$name = trim($name);
$value_type = detect_extender_valuetype($value, $value_type);
$owner_guid = (int) $owner_guid;
if ($owner_guid == 0) {
$owner_guid = elgg_get_logged_in_user_guid();
}
$access_id = (int) $access_id;
$value_id = elgg_get_metastring_id($value);
if (!$value_id) {
return false;
}
$name_id = elgg_get_metastring_id($name);
if (!$name_id) {
return false;
}
$result = update_data("UPDATE {$CONFIG->dbprefix}annotations\n\t\tSET name_id = {$name_id}, value_id = {$value_id}, value_type = '{$value_type}',\n\t\taccess_id = {$access_id}, owner_guid = {$owner_guid}\n\t\tWHERE id = {$annotation_id}");
if ($result !== false) {
// @todo add plugin hook that sends old and new annotation information before db access
$obj = elgg_get_annotation_from_id($annotation_id);
elgg_trigger_event('update', 'annotation', $obj);
}
return $result;
}
示例15: _elgg_shutdown_hook
/**
* Emits a shutdown:system event upon PHP shutdown, but before database connections are dropped.
*
* @tip Register for the shutdown:system event to perform functions at the end of page loads.
*
* @warning Using this event to perform long-running functions is not very
* useful. Servers will hold pages until processing is done before sending
* them out to the browser.
*
* @see http://www.php.net/register-shutdown-function
*
* @return void
* @see register_shutdown_hook()
* @access private
*/
function _elgg_shutdown_hook()
{
global $START_MICROTIME;
try {
elgg_trigger_event('shutdown', 'system');
$time = (double) (microtime(true) - $START_MICROTIME);
$uri = _elgg_services()->request->server->get('REQUEST_URI', 'CLI');
// demoted to NOTICE from DEBUG so javascript is not corrupted
elgg_log("Page {$uri} generated in {$time} seconds", 'INFO');
} catch (Exception $e) {
$message = 'Error: ' . get_class($e) . ' thrown within the shutdown handler. ';
$message .= "Message: '{$e->getMessage()}' in file {$e->getFile()} (line {$e->getLine()})";
error_log($message);
error_log("Exception trace stack: {$e->getTraceAsString()}");
}
// Prevent an APC session bug: https://bugs.php.net/bug.php?id=60657
session_write_close();
}