aboutsummaryrefslogtreecommitdiff
path: root/start.php
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2014-03-15 14:57:34 -0300
committerSilvio Rhatto <rhatto@riseup.net>2014-03-15 14:57:34 -0300
commit0be0b2d3a472b7b3a8c4a5d2ee22389acf126c3c (patch)
tree56d64a8ea726ce51df3790a7faf476d89e7c3fd8 /start.php
downloadelgg-0be0b2d3a472b7b3a8c4a5d2ee22389acf126c3c.tar.gz
elgg-0be0b2d3a472b7b3a8c4a5d2ee22389acf126c3c.tar.bz2
Squashed 'mod/autosubscribegroup/' content from commit 5e933d6
git-subtree-dir: mod/autosubscribegroup git-subtree-split: 5e933d6ede62fe62d2e6425e7b1e5fdc7d93d472
Diffstat (limited to 'start.php')
-rw-r--r--start.php57
1 files changed, 57 insertions, 0 deletions
diff --git a/start.php b/start.php
new file mode 100644
index 000000000..69f447267
--- /dev/null
+++ b/start.php
@@ -0,0 +1,57 @@
+<?php
+
+/**
+ * Elgg autosubscribegroup plugin
+ * This plugin allows new users to get joined to groups automatically when they register.
+ *
+ * @package autosubscribegroups
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
+ * @author RONNEL Jérémy
+ * @copyright (c) Elbee 2008
+ * @link /www.notredeco.com
+ *
+ * for Elgg 1.8 by iionly (iionly@gmx.de)
+ */
+
+/**
+ * Init
+ *
+ */
+function autosubscribegroup_init() {
+ //group plugin disabled : no need to go further...
+ if (!elgg_is_active_plugin("groups")) {
+ return;
+ }
+
+ //Listen to user registration
+ elgg_register_event_handler('create', 'user', 'autosubscribegroup_join', 502);
+}
+
+/**
+ * auto join group define in plugin settings
+ *
+ */
+function autosubscribegroup_join($event, $object_type, $object) {
+
+ if (($object instanceof ElggUser) && ($event == 'create') && ($object_type == 'user')) {
+ //auto submit relationships between user & groups
+ //retrieve groups ids from plugin
+ $groups = elgg_get_plugin_setting('systemgroups');
+ $groups = split(',', $groups);
+
+ //for each group ids
+ foreach($groups as $groupId) {
+ //if group exist : submit to group
+ if ($groupEnt = get_entity($groupId)) {
+ //join group succeed ?
+ if ($groupEnt->join($object)) {
+ // Remove any invite or join request flags
+ elgg_delete_metadata(array('guid' => $object->guid, 'metadata_name' => 'group_invite', 'metadata_value' => $groupEnt->guid, 'limit' => 0));
+ elgg_delete_metadata(array('guid' => $object->guid, 'metadata_name' => 'group_join_request', 'metadata_value' => $groupEnt->guid, 'limit' => 0));
+ }
+ }
+ }
+ }
+}
+
+elgg_register_event_handler('init', 'system', 'autosubscribegroup_init');