| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 | 
							- <?php
 
- /**
 
-  * Notification tools
 
-  */
 
- elgg_register_event_handler('init', 'system', 'notification_tools_init');
 
- /**
 
-  * Initialize the plugin
 
-  */
 
- function notification_tools_init () {
 
- 	$plugin_dir = elgg_get_plugins_path() . 'notification_tools/';
 
- 	elgg_register_action('notification_tools/enable_personal',  "{$plugin_dir}actions/notification_tools/enable_personal.php", 'admin');
 
- 	elgg_register_action('notification_tools/enable_collection',  "{$plugin_dir}actions/notification_tools/enable_collection.php", 'admin');
 
- 	elgg_register_action('notification_tools/enable_group',  "{$plugin_dir}actions/notification_tools/enable_group.php", 'admin');
 
- 	// This overrides the default save action
 
- 	elgg_register_action('notification_tools/settings/save',  "{$plugin_dir}actions/notification_tools/settings/save.php", 'admin');
 
- 	elgg_register_admin_menu_item('administer', 'notification_tools', 'administer_utilities');
 
- 	elgg_register_event_handler('join', 'group', 'notification_tools_enable_for_new_group_member');
 
- 	elgg_register_event_handler('create', 'user', 'notification_tools_enable_for_new_user');
 
- }
 
- /**
 
-  * Enable personal and friend notifications for new users
 
-  *
 
-  * We do this using 'create, user' event instead of 'register, user' plugin
 
-  * hook so that it affects also users created by an admin.
 
-  *
 
-  * @param  string   $event 'create'
 
-  * @param  string   $type  'user'
 
-  * @param  ElggUser $user
 
-  * @return boolean
 
-  */
 
- function notification_tools_enable_for_new_user ($event, $type, $user) {
 
- 	$personal = elgg_get_plugin_setting('default_personal_methods', 'notification_tools');
 
- 	// Set methods for personal notifications
 
- 	if ($personal) {
 
- 		$personal_methods = explode(',', $personal);
 
- 		foreach ($personal_methods as $method) {
 
- 			$prefix = "notification:method:{$method}";
 
- 			$user->$prefix = true;
 
- 		}
 
- 	}
 
- 	$collection = elgg_get_plugin_setting('default_collection_methods', 'notification_tools');
 
- 	// Set methods for notifications about friends' activity
 
- 	if ($collection) {
 
- 		$collection_methods = explode(',', $collection);
 
- 		// Here we just mark the default methods. The core notification plugin
 
- 		// will take care of creating the actual 'notify<method>' relationships
 
- 		// between user and each friends.
 
- 		foreach ($collection_methods as $method) {
 
- 			$setting_name = "collections_notifications_preferences_{$method}";
 
- 			// The -1 seems like a weird value but that's what the core
 
- 			// is using for whatever reason.
 
- 			$user->$setting_name = '-1';
 
- 		}
 
- 	}
 
- 	$user->save();
 
- 	return true;
 
- }
 
- /**
 
-  * Enable default notification methods when user joins a group
 
-  *
 
-  * @param string $event  'join'
 
-  * @param string $type   'group'
 
-  * @param array  $params Array containing ElggUser and ElggGroup
 
-  */
 
- function notification_tools_enable_for_new_group_member($event, $type, $params) {
 
- 	$group = $params['group'];
 
- 	$user = $params['user'];
 
- 	$methods = elgg_get_plugin_setting('default_group_methods', 'notification_tools');
 
- 	if (empty($methods)) {
 
- 		return true;
 
- 	}
 
- 	if (!$group instanceof ElggGroup) {
 
- 		return true;
 
- 	}
 
- 	if (!$user instanceof ElggUser) {
 
- 		return true;
 
- 	}
 
- 	$methods = explode(',', $methods);
 
- 	foreach ($methods as $method) {
 
- 		add_entity_relationship($user->guid, "notify{$method}", $group->guid);
 
- 	}
 
- 	return true;
 
- }
 
 
  |