/** * finds and accepts a users invites when registered within CB (front and backend) * * @param moscomprofilerUser $user */ public function acceptInvites( $user ) { $plugin = cbgjClass::getPlugin(); if ( $plugin->params->get( 'group_invites_accept', 1 ) ) { $invites = cbgjData::getInvites( null, array( 'email', '=', $user->email ) ); if ( $invites ) foreach ( $invites as $invite ) { $invite->set( 'accepted', cbgjClass::getUTCDate() ); $invite->set( 'user', (int) $user->id ); if ( $invite->store() ) { $row = cbgjData::getUsers( null, array( array( 'group', '=', (int) $invite->get( 'group' ) ), array( 'user_id', '=', (int) $user->id ) ), null, null, false ); if ( ! $row->get( 'id' ) ) { $row->set( 'user_id', (int) $user->id ); $row->set( 'group', (int) $invite->get( 'group' ) ); $row->set( 'date', cbgjClass::getUTCDate() ); $row->set( 'status', 1 ); $row->store(); } } $notification = cbgjData::getNotifications( array( array( 'grp_usr_notifications' ), 'owner' ), array( array( 'type', '=', 'group' ), array( 'item', '=', (int) $invite->get( 'group' ) ), array( 'user_id', '=', (int) $invite->get( 'user_id' ) ), array( 'params', 'CONTAINS', 'group_inviteaccept=1' ) ), null, null, false ); if ( $notification->get( 'id' ) ) { $subject = CBTxt::T( '[group_name] - Invite Accepted!' ); $message = CBTxt::T( '[user] has accepted your invite to join [group] in [category]!' ); cbgjClass::getNotification( $notification->get( 'user_id' ), $invite->get( 'user' ), $subject, $message, 1, $invite->getCategory(), $invite->getGroup() ); } } } }
private function getAuto( $user, $rawPassword, $extras, $trigger ) { $cbUser = new CBuser(); $cbUser->load( (int) $user->id ); if ( ( ! isset( $user->gids ) ) || ( isset( $user->gids ) && ( ! is_array( $user->gids ) ) ) ) { $gids = array( $user->gid ); } else { $gids = $user->gids; } if ( $user->id ) { array_unshift( $gids, -3 ); if ( isModerator( $user->id ) ) { array_unshift( $gids, -5 ); } else { array_unshift( $gids, -4 ); } } else { array_unshift( $gids, -2 ); } array_unshift( $gids, -1 ); $access = explode( '|*|', $trigger->get( 'access' ) ); if ( ! array_intersect( $access, $gids ) ) { return; } $conditionals = count( explode( "\n", $trigger->get( 'field' ) ) ); for ( $i = 0, $n = $conditionals; $i < $n; $i++ ) { if ( ! cbgjautoClass::getFieldMatch( $user, $cbUser, $extras, cbgjClass::getHTMLCleanParam( true, "field$i", null, null, $trigger->get( 'field' ) ), cbgjClass::getCleanParam( true, "operator$i", null, null, $trigger->get( 'operator' ) ), cbgjClass::getHTMLCleanParam( true, "value$i", null, null, $trigger->get( 'value' ) ) ) ) { return; } } $plugin = cbgjClass::getPlugin(); $exclude = $trigger->get( 'exclude' ); if ( $exclude ) { cbArrayToInts( explode( ',', $exclude ) ); $exclude = array_unique( $exclude ); if ( in_array( $user->id, $exclude ) ) { return; } } $params = $trigger->getParams(); if ( ( $params->get( 'auto', null ) == 3 ) && $params->get( 'cat_name', null ) ) { $owner = (int) $cbUser->replaceUserVars( $params->get( 'cat_owner', $user->id ), true, true, $extras ); if ( ! $owner ) { $owner = (int) $user->id; } $parent = (int) $params->get( 'cat_parent', 0 ); $name = trim( strip_tags( $cbUser->replaceUserVars( $params->get( 'cat_name', null ), true, true, $extras ) ) ); $description = $cbUser->replaceUserVars( $params->get( 'cat_description', null ), true, true, $extras ); if ( $params->get( 'cat_unique', 1 ) ) { $where = array( array( 'user_id', '=', $owner ), array( 'name', '=', $name ), array( 'parent', '=', (int) $parent ) ); } else { $where = array( array( 'name', '=', $name ), array( 'parent', '=', (int) $parent ) ); } $row = cbgjData::getCategories( null, $where, null, null, false ); if ( ! $row->get( 'id' ) ) { $row->set( 'published', 1 ); $row->set( 'parent', (int) $parent ); $row->set( 'user_id', $owner ); $row->set( 'name', $name ); if ( $plugin->params->get( 'category_editor', 1 ) >= 2 ) { $row->set( 'description', cbgjClass::getFilteredText( $description ) ); } else { $row->set( 'description', trim( strip_tags( $description ) ) ); } $row->set( 'access', (int) $plugin->params->get( 'category_access_default', -2 ) ); $row->set( 'types', $params->get( 'types', $plugin->params->get( 'category_types_default', '1|*|2|*|3' ) ) ); $row->set( 'create', (int) $plugin->params->get( 'category_create_default', 1 ) ); $row->set( 'create_access', (int) $plugin->params->get( 'category_createaccess_default', -1 ) ); $row->set( 'nested', (int) $plugin->params->get( 'category_nested_default', 1 ) ); $row->set( 'nested_access', (int) $plugin->params->get( 'category_nestedaccess_default', -1 ) ); $row->set( 'date', cbgjClass::getUTCDate() ); $row->set( 'ordering', 99999 ); $row->store(); } } elseif ( ( $params->get( 'auto', null ) == 2 ) && $params->get( 'category', null ) && $params->get( 'grp_name', null ) ) { if ( ( $params->get( 'category', null ) == -1 ) && $params->get( 'cat_name', null ) ) { $owner = (int) $cbUser->replaceUserVars( $params->get( 'cat_owner', $user->id ), true, true, $extras ); if ( ! $owner ) { $owner = (int) $user->id; } $parent = (int) $params->get( 'cat_parent', 0 ); $name = trim( strip_tags( $cbUser->replaceUserVars( $params->get( 'cat_name', null ), true, true, $extras ) ) ); $description = $cbUser->replaceUserVars( $params->get( 'cat_description', null ), true, true, $extras ); if ( $params->get( 'cat_unique', 1 ) ) { $where = array( array( 'user_id', '=', $owner ), array( 'name', '=', $name ), array( 'parent', '=', (int) $parent ) ); } else { $where = array( array( 'name', '=', $name ), array( 'parent', '=', (int) $parent ) ); } $category = cbgjData::getCategories( null, $where, null, null, false ); if ( ! $category->get( 'id' ) ) { $category->set( 'published', 1 ); $category->set( 'parent', (int) $parent ); $category->set( 'user_id', $owner ); $category->set( 'name', $name ); if ( $plugin->params->get( 'category_editor', 1 ) >= 2 ) { $category->set( 'description', cbgjClass::getFilteredText( $description ) ); } else { $category->set( 'description', trim( strip_tags( $description ) ) ); } $category->set( 'access', (int) $plugin->params->get( 'category_access_default', -2 ) ); $category->set( 'types', $params->get( 'types', $plugin->params->get( 'category_types_default', '1|*|2|*|3' ) ) ); $category->set( 'create', (int) $plugin->params->get( 'category_create_default', 1 ) ); $category->set( 'create_access', (int) $plugin->params->get( 'category_createaccess_default', -1 ) ); $category->set( 'nested', (int) $plugin->params->get( 'category_nested_default', 1 ) ); $category->set( 'nested_access', (int) $plugin->params->get( 'category_nestedaccess_default', -1 ) ); $category->set( 'date', cbgjClass::getUTCDate() ); $category->set( 'ordering', 99999 ); $category->store(); } } else { $category = cbgjData::getCategories( null, array( 'id', '=', (int) $params->get( 'category', null ) ), null, null, false ); } if ( $category->get( 'id' ) ) { $owner = (int) $cbUser->replaceUserVars( $params->get( 'grp_owner', $user->id ), true, true, $extras ); if ( ! $owner ) { $owner = (int) $user->id; } $parent = (int) $params->get( 'grp_parent', 0 ); $name = trim( strip_tags( $cbUser->replaceUserVars( $params->get( 'grp_name', null ), true, true, $extras ) ) ); $description = $cbUser->replaceUserVars( $params->get( 'grp_description', null ), true, true, $extras ); $join = false; if ( $params->get( 'grp_unique', 1 ) ) { $where = array( array( 'category', '=', (int) $category->get( 'id' ) ), array( 'user_id', '=', $owner ), array( 'name', '=', $name ), array( 'parent', '=', (int) $parent ) ); } else { $where = array( array( 'category', '=', (int) $category->get( 'id' ) ), array( 'name', '=', $name ), array( 'parent', '=', (int) $parent ) ); if ( $params->get( 'grp_autojoin', 1 ) ) { $join = true; } } $row = cbgjData::getGroups( null, $where, null, null, false ); if ( ! $row->get( 'id' ) ) { $row->set( 'published', 1 ); $row->set( 'category', (int) $category->get( 'id' ) ); $row->set( 'parent', (int) $parent ); $row->set( 'user_id', $owner ); $row->set( 'name', $name ); if ( $plugin->params->get( 'group_editor', 1 ) >= 2 ) { $row->set( 'description', cbgjClass::getFilteredText( $description ) ); } else { $row->set( 'description', trim( strip_tags( $description ) ) ); } $row->set( 'access', (int) $plugin->params->get( 'group_access_default', -2 ) ); $row->set( 'type', (int) $params->get( 'type', $plugin->params->get( 'group_type_default', 1 ) ) ); $row->set( 'nested', (int) $plugin->params->get( 'group_nested_default', 1 ) ); $row->set( 'nested_access', (int) $plugin->params->get( 'group_nestedaccess_default', -1 ) ); $row->set( 'date', cbgjClass::getUTCDate() ); $row->set( 'ordering', 1 ); if ( $row->store() ) { $row->storeOwner( $row->get( 'user_id' ) ); if ( $row->get( 'user_id' ) != $user->id ) { $usr = cbgjData::getUsers( null, array( array( 'group', '=', (int) $row->get( 'id' ) ), array( 'user_id', '=', (int) $user->id ) ), null, null, false ); if ( ! $usr->get( 'id' ) ) { $usr->set( 'user_id', (int) $user->id ); $usr->set( 'group', (int) $row->get( 'id' ) ); $usr->set( 'date', cbgjClass::getUTCDate() ); $usr->set( 'status', 1 ); $usr->store(); } } } } elseif ( $join ) { $usr = cbgjData::getUsers( null, array( array( 'group', '=', (int) $row->get( 'id' ) ), array( 'user_id', '=', (int) $user->id ) ), null, null, false ); if ( ! $usr->get( 'id' ) ) { $usr->set( 'user_id', (int) $user->id ); $usr->set( 'group', (int) $row->get( 'id' ) ); $usr->set( 'date', cbgjClass::getUTCDate() ); $usr->set( 'status', (int) $params->get( 'status', 1 ) ); if ( $usr->store() ) { if ( $usr->get( 'status' ) == 4 ) { $row->storeOwner( $usr->get( 'user_id' ) ); } } } } } } elseif ( ( $params->get( 'auto', null ) == 1 ) && $params->get( 'groups', null ) ) { $groups = $params->get( 'groups', null ); if ( $groups ) { $groups = explode( '|*|', $groups ); cbArrayToInts( $groups ); } if ( $groups ) foreach ( $groups as $groupId ) { $group = cbgjData::getGroups( null, array( 'id', '=', (int) $groupId ), null, null, false ); if ( $group->get( 'id' ) ) { $row = cbgjData::getUsers( null, array( array( 'group', '=', (int) $group->get( 'id' ) ), array( 'user_id', '=', (int) $user->id ) ), null, null, false ); if ( ! $row->get( 'id' ) ) { $row->set( 'user_id', (int) $user->id ); $row->set( 'group', (int) $group->get( 'id' ) ); $row->set( 'date', cbgjClass::getUTCDate() ); $row->set( 'status', (int) $params->get( 'status', 1 ) ); if ( $row->store() ) { if ( $row->get( 'status' ) == 4 ) { $group->storeOwner( $row->get( 'user_id' ) ); } } } } } } elseif ( ( $params->get( 'auto', null ) == 4 ) && $params->get( 'groups', null ) ) { $groups = $params->get( 'groups', null ); if ( $groups ) { $groups = explode( '|*|', $groups ); cbArrayToInts( $groups ); } if ( $groups ) foreach ( $groups as $groupId ) { $group = cbgjData::getGroups( null, array( 'id', '=', (int) $groupId ), null, null, false ); if ( $group->get( 'id' ) ) { $row = cbgjData::getUsers( null, array( array( 'group', '=', (int) $group->get( 'id' ) ), array( 'user_id', '=', (int) $user->id ) ), null, null, false ); if ( $row->get( 'id' ) && ( $row->get( 'status' ) != 4 ) ) { $row->deleteAll(); } } } } }
/** * render backend user edit * * @param object $row * @param object $group * @param object $category * @param array $input * @param moscomprofilerUser $user * @param object $plugin */ static public function showUserEdit( $row, $group, $category, $input, $user, $plugin ) { global $_CB_framework; if ( $row->get( 'id' ) ) { $title = CBTxt::P( 'Users: <small>Edit [[user_id]]</small>', array( '[user_id]' => (int) $row->get( 'user_id' ) ) ); } else { $title = CBTxt::T( 'Users: <small>New</small>' ); } HTML_cbgjAdmin::setTitle( $title, 'cbicon-48-gjusers' ); $return = '<form action="' . $_CB_framework->backendUrl( 'index.php' ) . '" method="post" name="adminForm" enctype="multipart/form-data" id="adminForm" class="adminform">' . '<table class="adminlist" width="100%" cellspacing="0" cellpadding="4" border="0">' . '<tbody>' . '<tr>' . '<td width="15%">' . CBTxt::Th( 'User' ) . '</td>' . '<td width="40%">' . $input['user'] . '</td>' . '<td>' . CBTxt::Th( 'Input comma separated list of user ids of the users to join the specified group (e.g. 62,43,29).' ) . '</td>' . '</tr>' . '<tr>' . '<td width="15%">' . CBTxt::Th( 'Group' ) . '</td>' . '<td width="40%">' . $input['group'] . '</td>' . '<td>' . CBTxt::Th( 'Select group the specified user is to join.' ) . '</td>' . '</tr>' . '<tr>' . '<td width="15%">' . CBTxt::Th( 'Status' ) . '</td>' . '<td width="40%">' . $input['status'] . '</td>' . '<td>' . CBTxt::Th( 'Select status of the user for the specified group.' ) . '</td>' . '</tr>' . '</tbody>' . '</table>' . '<input type="hidden" id="id" name="id" value="' . (int) $row->get( 'id' ) . '" />' . '<input type="hidden" id="date" name="date" value="' . htmlspecialchars( $row->get( 'date', cbgjClass::getUTCDate() ) ) . '" />' . '<input type="hidden" id="option" name="option" value="' . htmlspecialchars( $plugin->option ) . '" />' . '<input type="hidden" id="task" name="task" value="editPlugin" />' . '<input type="hidden" id="cid" name="cid" value="' . (int) $plugin->id . '" />' . '<input type="hidden" id="action" name="action" value="users.save" />' . cbGetSpoofInputTag( 'plugin' ) . '</form>'; echo $return; }
/** * accepts all invites belonging to the user or invite code supplied * * @param string|null $code * @return bool */ public function acceptInvites( $code = null ) { $invites = $this->getUnacceptedInvites( $code ); if ( $invites ) foreach ( $invites as $invite ) { $invite->set( 'accepted', cbgjClass::getUTCDate() ); $invite->set( 'user', (int) $this->get( 'user_id' ) ); if ( ! $invite->store() ) { return false; } } return true; }
/** * migrate old groupjive data * * @param moscomprofilerUser $user * @param object $plugin */ private function showMigrate( $user, $plugin ) { global $_CB_framework, $_CB_database; $gj_categories = $_CB_database->getTableStatus( '#__gj_grcategory' ); $gj_groups = $_CB_database->getTableStatus( '#__gj_groups' ); $gj_users = $_CB_database->getTableStatus( '#__gj_users' ); $gj_path = $_CB_framework->getCfg( 'absolute_path' ) . '/images/com_groupjive'; if ( $gj_categories ) { $query = 'SELECT *' . "\n FROM " . $_CB_database->NameQuote( '#__gj_grcategory' ); $_CB_database->setQuery( $query ); $categories = $_CB_database->loadObjectList(); if ( $categories ) foreach ( $categories as $category ) { $cat = new cbgjCategory( $_CB_database ); $types = array(); if ( $category->create_open ) { $types[] = 1; } if ( $category->create_closed ) { $types[] = 2; } if ( $category->create_invite ) { $types[] = 3; } $cat->set( 'user_id', (int) ( $category->admin ? $category->admin : $user->id ) ); $cat->set( 'name', trim( strip_tags( $category->catname ) ) ); if ( $plugin->params->get( 'category_editor', 1 ) >= 2 ) { $cat->set( 'description', cbgjClass::getFilteredText( $category->descr ) ); } else { $cat->set( 'description', trim( strip_tags( $category->descr ) ) ); } $cat->set( 'types', ( is_array( $types ) ? implode( '|*|', $types ) : null ) ); $cat->set( 'date', cbgjClass::getUTCDate() ); $cat->set( 'ordering', (int) $category->ordering ); $cat->set( 'published', (int) $category->published ); if ( $category->access == 2 ) { $cat->set( 'access', 30 ); } elseif ( $category->access == 1 ) { $cat->set( 'access', -1 ); } else { $cat->set( 'access', -2 ); } if ( ! $cat->store() ) { cbgjClass::getPluginURL( array( 'tools' ), CBTxt::P( 'Category failed to migrate! Error: [error]', array( '[error]' => $cat->getError() ) ), false, true, 'error' ); } $cat_path = $plugin->imgsAbs . '/' . (int) $cat->get( 'id' ); if ( $category->cat_image ) { $mode = cbgjClass::getFilePerms(); if ( ! is_dir( $cat_path ) ) { $oldmask = @umask( 0 ); if ( @mkdir( $cat_path, cbgjClass::getFolderPerms(), true ) ) { @umask( $oldmask ); if ( ! file_exists( $plugin->imgsAbs . '/index.html' ) ) { @copy( $plugin->absPath . '/images/index.html', $plugin->imgsAbs . '/index.html' ); @chmod( $plugin->imgsAbs . '/index.html', $mode ); } if ( ! file_exists( $cat_path . '/index.html' ) ) { @copy( $plugin->absPath . '/images/index.html', $cat_path . '/index.html' ); @chmod( $cat_path . '/index.html', $mode ); } } else { @umask( $oldmask ); } } if ( file_exists( $gj_path . '/' . $category->cat_image ) && ( ! file_exists( $cat_path . '/' . $category->cat_image ) ) ) { @copy( $gj_path . '/' . $category->cat_image, $cat_path . '/' . $category->cat_image ); @chmod( $cat_path . '/' . $category->cat_imag, $mode ); } if ( file_exists( $gj_path . '/tn' . $category->cat_image ) && ( ! file_exists( $cat_path . '/tn' . $category->cat_image ) ) ) { @copy( $gj_path . '/tn' . $category->cat_image, $cat_path . '/tn' . $category->cat_image ); @chmod( $cat_path . '/tn' . $category->cat_image, $mode ); } if ( file_exists( $cat_path . $category->cat_image ) && file_exists( $cat_path . 'tn' . $category->cat_image ) ) { $cat->set( 'logo', $category->cat_image ); } } if ( $gj_groups ) { $query = 'SELECT *' . "\n FROM " . $_CB_database->NameQuote( '#__gj_groups' ) . "\n WHERE " . $_CB_database->NameQuote( 'category' ) . " = " . (int) $cat->get( 'id' ); $_CB_database->setQuery( $query ); $groups = $_CB_database->loadObjectList(); if ( $groups ) foreach ( $groups as $group ) { $grp = new cbgjGroup( $_CB_database ); $grp->set( 'user_id', (int) ( $group->user_id ? $group->user_id : $user->id ) ); $grp->set( 'name', trim( strip_tags( $group->name ) ) ); if ( $plugin->params->get( 'group_editor', 1 ) >= 2 ) { $grp->set( 'description', cbgjClass::getFilteredText( $group->descr ) ); } else { $grp->set( 'description', trim( strip_tags( $group->descr ) ) ); } $grp->set( 'type', (int) $group->type ); $grp->set( 'date', $group->date_s ); $grp->set( 'category', $cat->get( 'id' ) ); $grp->set( 'published', (int) $group->active ); $grp->set( 'access', -2 ); if ( ! $grp->store() ) { cbgjClass::getPluginURL( array( 'tools' ), CBTxt::P( 'Group failed to migrate! Error: [error]', array( '[error]' => $grp->getError() ) ), false, true, 'error' ); } $grp_path = $plugin->imgsAbs . '/' . (int) $cat->get( 'id' ) . '/' . (int) $grp->get( 'id' ); if ( $group->logo ) { $mode = cbgjClass::getFilePerms(); if ( ! is_dir( $grp_path ) ) { $oldmask = @umask( 0 ); if ( @mkdir( $grp_path, cbgjClass::getFolderPerms(), true ) ) { @umask( $oldmask ); if ( ! file_exists( $plugin->imgsAbs . '/index.html' ) ) { @copy( $plugin->absPath . '/images/index.html', $plugin->imgsAbs . '/index.html' ); @chmod( $plugin->imgsAbs . '/index.html', $mode ); } if ( ! file_exists( $cat_path . '/index.html' ) ) { @copy( $plugin->absPath . '/images/index.html', $cat_path . '/index.html' ); @chmod( $cat_path . '/index.html', $mode ); } if ( ! file_exists( $grp_path . '/index.html' ) ) { @copy( $plugin->absPath . '/images/index.html', $grp_path . '/index.html' ); @chmod( $grp_path . '/index.html', $mode ); } } else { @umask( $oldmask ); } } if ( file_exists( $gj_path . '/' . $group->logo ) && ( ! file_exists( $grp_path . '/' . $group->logo ) ) ) { @copy( $gj_path . '/' . $group->logo, $grp_path . '/' . $group->logo ); @chmod( $grp_path . '/' . $group->logo, $mode ); } if ( file_exists( $gj_path . '/tn' . $group->logo ) && ( ! file_exists( $grp_path . '/tn' . $group->logo ) ) ) { @copy( $gj_path . '/tn' . $group->logo, $grp_path . '/tn' . $group->logo ); @chmod( $grp_path . '/tn' . $group->logo, $mode ); } if ( file_exists( $grp_path . $group->logo ) && file_exists( $grp_path . 'tn' . $group->logo ) ) { $grp->set( 'logo', $group->logo ); } } $owner = new cbgjUser( $_CB_database ); $owner->set( 'user_id', (int) $grp->get( 'user_id' ) ); $owner->set( 'group', (int) $grp->get( 'id' ) ); $owner->set( 'date', $grp->get( 'date' ) ); $owner->set( 'status', 4 ); if ( ! $owner->store() ) { cbgjClass::getPluginURL( array( 'tools' ), CBTxt::P( 'Owner failed to migrate! Error: [error]', array( '[error]' => $owner->getError() ) ), false, true, 'error' ); } if ( $gj_users ) { $query = 'SELECT *' . "\n FROM " . $_CB_database->NameQuote( '#__gj_users' ) . "\n WHERE " . $_CB_database->NameQuote( 'id_group' ) . " = " . (int) $grp->get( 'id' ) . "\n AND " . $_CB_database->NameQuote( 'id_user' ) . " != " . (int) $grp->get( 'user_id' ); $_CB_database->setQuery( $query ); $users = $_CB_database->loadObjectList(); if ( $users ) foreach ( $users as $u ) { $usr = new cbgjUser( $_CB_database ); $usr->set( 'user_id', (int) $u->id_user ); $usr->set( 'group', (int) $grp->get( 'id' ) ); $usr->set( 'date', $u->date ); $usr->set( 'status', ( $u->status == 'active' ? 1 : 0 ) ); if ( ! $usr->store() ) { cbgjClass::getPluginURL( array( 'tools' ), CBTxt::P( 'User failed to migrate! Error: [error]', array( '[error]' => $usr->getError() ) ), false, true, 'error' ); } } } } } } } else { cbgjClass::getPluginURL( array( 'tools' ), CBTxt::T( 'Nothing to migrate.' ), false, true, 'error' ); } cbgjClass::getPluginURL( array( 'tools' ), CBTxt::T( 'GroupJive migration successful.' ), false, true ); }