/** * save invite * * @param int $id * @param UserTable $user */ private function saveInviteEdit( $id, $user ) { global $_CB_framework, $_CB_database, $_PLUGINS; $row = new InviteTable(); $row->load( (int) $id ); $isModerator = CBGroupJive::isModerator( $user->get( 'id' ) ); $groupId = $this->input( 'group', null, GetterInterface::INT ); if ( $groupId === null ) { $group = $row->group(); } else { $group = CBGroupJive::getGroup( $groupId ); } $returnUrl = $_CB_framework->pluginClassUrl( $this->element, false, array( 'action' => 'groups', 'func' => 'show', 'id' => (int) $group->get( 'id' ) ) ); if ( ! CBGroupJive::canAccessGroup( $group, $user ) ) { cbRedirect( $returnUrl, CBTxt::T( 'Group does not exist.' ), 'error' ); } elseif ( $row->get( 'id' ) && ( $user->get( 'id' ) != $row->get( 'user_id' ) ) ) { cbRedirect( $returnUrl, CBTxt::T( 'You do not have sufficient permissions to edit this invite.' ), 'error' ); } elseif ( ! $isModerator ) { if ( ( $group->get( 'published' ) == -1 ) || ( ( ! $this->params->get( 'groups_invites_display', 1 ) ) && ( $group->get( 'type' ) != 3 ) ) ) { cbRedirect( $returnUrl, CBTxt::T( 'You do not have access to invites in this group.' ), 'error' ); } elseif ( ( ! $row->get( 'id' ) ) && ( ! CBGroupJive::canCreateGroupContent( $user, $group, 'invites' ) ) ) { cbRedirect( $returnUrl, CBTxt::T( 'You do not have sufficient permissions to create an invite in this group.' ), 'error' ); } } $skipCaptcha = false; $row->set( 'message', $this->input( 'post/message', $row->get( 'message' ), GetterInterface::STRING ) ); if ( ! $row->get( 'id' ) ) { $row->set( 'user_id', (int) $row->get( 'user_id', $user->get( 'id' ) ) ); $row->set( 'group', (int) $group->get( 'id' ) ); $to = $this->input( 'post/to', null, GetterInterface::STRING ); $selected = (int) $this->input( 'post/selected', 0, GetterInterface::INT ); if ( $selected ) { $token = $this->input( 'post/token', null, GetterInterface::STRING ); if ( $token ) { if ( $token == md5( $row->get( 'user_id' ) . $to . $row->get( 'group' ) . $row->get( 'message' ) . $_CB_framework->getCfg( 'secret' ) ) ) { $skipCaptcha = true; $row->set( 'user', (int) $selected ); } } elseif ( $this->params->get( 'groups_invites_list', 0 ) ) { $connections = array(); $cbConnection = new cbConnection( (int) $user->get( 'id' ) ); foreach( $cbConnection->getConnectedToMe( (int) $user->get( 'id' ) ) as $connection ) { $connections[] = (int) $connection->id; } if ( in_array( $selected, $connections ) ) { $row->set( 'user', (int) $selected ); } } } else { $inviteByLimit = explode( '|*|', $this->params->get( 'groups_invites_by', '1|*|2|*|3|*|4' ) ); if ( ! $inviteByLimit ) { $inviteByLimit = array( 1, 2, 3, 4 ); } $recipient = new UserTable(); if ( in_array( 1, $inviteByLimit ) && $recipient->load( (int) $to ) ) { $row->set( 'user', (int) $recipient->get( 'id' ) ); } elseif ( in_array( 4, $inviteByLimit ) && cbIsValidEmail( $to ) ) { if ( $recipient->load( array( 'email' => $to ) ) ) { $row->set( 'user', (int) $recipient->get( 'id' ) ); } else { $row->set( 'email', $to ); } } elseif ( in_array( 2, $inviteByLimit ) && $recipient->load( array( 'username' => $to ) ) ) { $row->set( 'user', (int) $recipient->get( 'id' ) ); } elseif ( in_array( 3, $inviteByLimit ) ) { $query = 'SELECT cb.' . $_CB_database->NameQuote( 'id' ) . "\n FROM " . $_CB_database->NameQuote( '#__comprofiler' ) . " AS cb" . "\n LEFT JOIN " . $_CB_database->NameQuote( '#__users' ) . " AS j" . ' ON j.' . $_CB_database->NameQuote( 'id' ) . ' = cb.' . $_CB_database->NameQuote( 'id' ) . "\n LEFT JOIN " . $_CB_database->NameQuote( '#__groupjive_users' ) . " AS u" . ' ON u.' . $_CB_database->NameQuote( 'user_id' ) . ' = cb.' . $_CB_database->NameQuote( 'id' ) . ' AND u.' . $_CB_database->NameQuote( 'group' ) . ' = ' . (int) $group->get( 'id' ) . "\n LEFT JOIN " . $_CB_database->NameQuote( '#__groupjive_invites' ) . " AS i" . ' ON i.' . $_CB_database->NameQuote( 'group' ) . ' = ' . (int) $group->get( 'id' ) . ' AND i.' . $_CB_database->NameQuote( 'user' ) . ' = cb.' . $_CB_database->NameQuote( 'id' ) . "\n WHERE j." . $_CB_database->NameQuote( 'name' ) . " LIKE " . $_CB_database->Quote( '%' . $_CB_database->getEscaped( $to, true ) . '%', false ) . "\n AND cb." . $_CB_database->NameQuote( 'approved' ) . " = 1" . "\n AND cb." . $_CB_database->NameQuote( 'confirmed' ) . " = 1" . "\n AND j." . $_CB_database->NameQuote( 'block' ) . " = 0" . "\n AND u." . $_CB_database->NameQuote( 'id' ) . " IS NULL" . "\n AND i." . $_CB_database->NameQuote( 'id' ) . " IS NULL" . "\n ORDER BY j." . $_CB_database->NameQuote( 'registerDate' ) . " DESC"; $_CB_database->setQuery( $query, 0, 15 ); $users = $_CB_database->loadResultArray(); if ( $users ) { if ( count( $users ) > 1 ) { CBGroupJive::getTemplate( 'invite_list' ); CBuser::advanceNoticeOfUsersNeeded( $users ); HTML_groupjiveInviteList::showInviteList( $to, $users, $row, $group, $user, $this ); return; } else { $row->set( 'user', (int) $users[0] ); } } } } } if ( ( ! $isModerator ) && $this->params->get( 'groups_create_captcha', 0 ) && ( ! $skipCaptcha ) ) { $_PLUGINS->loadPluginGroup( 'user' ); $_PLUGINS->trigger( 'onCheckCaptchaHtmlElements', array() ); if ( $_PLUGINS->is_errors() ) { $row->setError( $_PLUGINS->getErrorMSG() ); } } $new = ( $row->get( 'id' ) ? false : true ); if ( $row->getError() || ( ! $row->check() ) ) { $_CB_framework->enqueueMessage( CBTxt::T( 'GROUP_INVITE_FAILED_TO_SAVE', 'Invite failed to save! Error: [error]', array( '[error]' => $row->getError() ) ), 'error' ); $this->showInviteEdit( $id, $user ); return; } if ( $row->getError() || ( ! $row->store() ) ) { $_CB_framework->enqueueMessage( CBTxt::T( 'GROUP_INVITE_FAILED_TO_SAVE', 'Invite failed to save! Error: [error]', array( '[error]' => $row->getError() ) ), 'error' ); $this->showInviteEdit( $id, $user ); return; } if ( $new ) { cbRedirect( $returnUrl, CBTxt::T( 'Invite created successfully!' ) ); } else { cbRedirect( $returnUrl, CBTxt::T( 'Invite saved successfully!' ) ); } }
function manageConnections($userid) { global $_CB_framework, $ueConfig, $_PLUGINS; if (!$ueConfig['allowConnections']) { $msg = CBTxt::Th('UE_FUNCTIONALITY_DISABLED', 'This functionality is currently disabled.'); } elseif ($_CB_framework->myId() != $userid || $_CB_framework->myId() == 0) { $msg = CBTxt::Th('UE_NOT_AUTHORIZED', 'You are not authorized to view this page!'); } else { $msg = null; } $_PLUGINS->loadPluginGroup('user'); $_PLUGINS->trigger('onBeforeManageConnectionsRequest', array($userid, &$msg)); if ($msg) { $_CB_framework->enqueueMessage($msg, 'error'); return; } $cbCon = new cbConnection($userid); $tabs = new cbTabs(0, $_CB_framework->getUi()); $tabs->element = ''; $pagingParams = $tabs->_getPaging(array(), array('connections_')); $perpage = 20; //TBD unhardcode and get the code below better $total = $cbCon->getConnectionsCount($userid, true); if ($pagingParams["connections_limitstart"] === null) { $pagingParams["connections_limitstart"] = 0; } if ($pagingParams["connections_limitstart"] > $total) { $pagingParams["connections_limitstart"] = 0; } $offset = $pagingParams["connections_limitstart"] ? (int) $pagingParams["connections_limitstart"] : 0; $connections = $cbCon->getActiveConnections($userid, $offset, $perpage); $actions = $cbCon->getPendingConnections($userid); $connecteds = $cbCon->getConnectedToMe($userid); HTML_comprofiler::manageConnections($connections, $actions, $total, $tabs, $pagingParams, $perpage, $connecteds); }
function manageConnections($userid) { global $_CB_framework, $ueConfig; if(!$ueConfig['allowConnections']) { echo _UE_FUNCTIONALITY_DISABLED; return; } if ( $_CB_framework->myId() != $userid || $_CB_framework->myId() == 0) { cbNotAuth(); return; } $cbCon = new cbConnection( $userid ); $connections = $cbCon->getActiveConnections( $userid ); $tabs = new cbTabs( 0, $_CB_framework->getUi() ); $tabs->element = ''; $pagingParams = $tabs->_getPaging( array(), array( 'connections_' ) ); $perpage = 20; //TBD unhardcode and get the code below better $total = $cbCon->getConnectionsCount( $userid, true ); if ( $pagingParams["connections_limitstart"] === null ) { $pagingParams["connections_limitstart"] = 0; } if ( $pagingParams["connections_limitstart"] > $total ) { $pagingParams["connections_limitstart"] = 0; } $offset = ( $pagingParams["connections_limitstart"] ? (int) $pagingParams["connections_limitstart"] : 0 ); $connections = $cbCon->getActiveConnections( $userid, $offset, $perpage ); $actions = $cbCon->getPendingConnections( $userid ); $connecteds = $cbCon->getConnectedToMe( $userid ); HTML_comprofiler::manageConnections( $connections, $actions, $total, $tabs, $pagingParams, $perpage, $connecteds ); }
/** * Returns an options array of available user tags with optional activity specific * * @param null|int|ActivityTable $activityId * @param null|int $userId * @return array */ static public function loadTagOptions( $activityId = null, $userId = null ) { global $_CB_database; /** @var ActivityTable[] $cache */ static $cache = array(); if ( $activityId && ( $userId === null ) ) { if ( $activityId instanceof ActivityTable ) { $activity = $activityId; $activityId = (int) $activity->get( 'id' ); } else { if ( ! isset( $cache[$activityId] ) ) { $activity = new ActivityTable(); $activity->load( (int) $activityId ); $cache[$activityId] = $activity; } $activity = $cache[$activityId]; } $userId = (int) $activity->get( 'user_id' ); } elseif ( $userId === null ) { $userId = Application::MyUser()->getUserId(); } static $connections = array(); static $custom = array(); static $options = array(); if ( ! isset( $options[$userId][$activityId] ) ) { if ( ! isset( $connections[$userId] ) ) { $connectionOptions = array(); if ( Application::Config()->get( 'allowConnections' ) ) { $cbConnection = new \cbConnection( $userId ); foreach( $cbConnection->getConnectedToMe( $userId ) as $connection ) { $connectionOptions[] = \moscomprofilerHTML::makeOption( (string) $connection->id, getNameFormat( $connection->name, $connection->username, Application::Config()->get( 'name_format', 3 ) ) ); } } $connections[$userId] = $connectionOptions; } if ( ! isset( $custom[$activityId] ) ) { $activityOptions = array(); if ( $activityId ) { $exclude = array(); foreach ( $connections[$userId] as $connection ) { $exclude[] = $connection->value; } $query = 'SELECT *' . "\n FROM " . $_CB_database->NameQuote( '#__comprofiler_plugin_activity_tags' ) . "\n WHERE " . $_CB_database->NameQuote( 'type' ) . " = " . $_CB_database->Quote( 'activity' ) . "\n AND " . $_CB_database->NameQuote( 'item' ) . " = " . (int) $activityId . "\n ORDER BY " . $_CB_database->NameQuote( 'date' ) . " ASC"; $_CB_database->setQuery( $query ); $tags = $_CB_database->loadObjectList( null, '\CB\Plugin\Activity\Table\TagTable', array( $_CB_database ) ); /** @var TagTable[] $tags */ foreach ( $tags as $tag ) { if ( ! in_array( $tag->get( 'user' ), $exclude ) ) { $activityOptions[] = \moscomprofilerHTML::makeOption( (string) $tag->get( 'user' ), $tag->get( 'user' ) ); } } } $custom[$activityId] = $activityOptions; } $options[$userId][$activityId] = array_merge( $connections[$userId], $custom[$activityId] ); } return $options[$userId][$activityId]; }