/** * @param cbautoactionsActionTable $trigger * @param UserTable $user */ public function execute( $trigger, $user ) { global $_CB_database; if ( ! $user->get( 'id' ) ) { if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) { var_dump( CBTxt::T( 'AUTO_ACTION_FIELD_NO_USER', ':: Action [action] :: Field skipped due to no user', array( '[action]' => (int) $trigger->get( 'id' ) ) ) ); } return; } foreach ( $trigger->getParams()->subTree( 'field' ) as $row ) { /** @var ParamsInterface $row */ $fieldId = $row->get( 'field', null, GetterInterface::INT ); if ( ! $fieldId ) { if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) { var_dump( CBTxt::T( 'AUTO_ACTION_FIELD_NO_FIELD', ':: Action [action] :: Field skipped due to missing field', array( '[action]' => (int) $trigger->get( 'id' ) ) ) ); } continue; } /** @var FieldTable[] $fields */ static $fields = array(); if ( ! isset( $fields[$fieldId] ) ) { $field = new FieldTable(); $field->load( (int) $fieldId ); $fields[$fieldId] = $field; } if ( ! $fields[$fieldId] ) { if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) { var_dump( CBTxt::T( 'AUTO_ACTION_FIELD_DOES_NOT_EXIST', ':: Action [action] :: Field skipped due to field [field_id] does not exist', array( '[action]' => (int) $trigger->get( 'id' ), '[field_id]' => (int) $fieldId ) ) ); } continue; } $operator = $row->get( 'operator', 'set', GetterInterface::STRING ); $value = $trigger->getSubstituteString( $row->get( 'value', null, GetterInterface::RAW ), false, $row->get( 'translate', false, GetterInterface::BOOLEAN ) ); $fieldName = $fields[$fieldId]->get( 'name' ); $fieldColumn = $_CB_database->NameQuote( $fieldName ); if ( ( ! in_array( $fields[$fieldId]->get( 'type' ), array( 'integer', 'counter' ) ) ) && in_array( $operator, array( 'add', 'subtract', 'divide', 'multiply' ) ) ) { $operator = 'set'; } switch ( $operator ) { case 'prefix': $fieldValue = ( $value . $user->get( $fieldName ) ); break; case 'suffix': $fieldValue = ( $user->get( $fieldName ) . $value ); break; case 'add': $fieldValue = ( (int) $user->get( $fieldName ) + (int) $value ); break; case 'subtract': $fieldValue = ( (int) $user->get( $fieldName ) - (int) $value ); break; case 'divide': $fieldValue = ( (int) $user->get( $fieldName ) / (int) $value ); break; case 'multiply': $fieldValue = ( (int) $user->get( $fieldName ) * (int) $value ); break; case 'set': default: $fieldValue = $value; break; } $query = 'UPDATE ' . $_CB_database->NameQuote( $fields[$fieldId]->get( 'table' ) ) . "\n SET " . $fieldColumn . " = " . $_CB_database->Quote( $fieldValue ) . "\n WHERE " . $_CB_database->NameQuote( 'id' ) . " = " . (int) $user->get( 'id' ); $_CB_database->setQuery( $query ); $_CB_database->query(); $user->set( $fieldName, $fieldValue ); } }
/** * Direct access to field for custom operations, like for Ajax * * WARNING: direct unchecked access, except if $user is set, then check well for the $reason ... * * @param FieldTable $field * @param UserTable $user * @param array $postdata * @param string $reason 'profile' for user profile view, 'edit' for profile edit, 'register' for registration, 'search' for searches * @return string Expected output. */ public function getAjaxResponse( &$field, &$user, &$postdata, $reason ) { global $_CB_framework, $_CB_database, $_PLUGINS, $ueConfig; if ( ( cbGetParam( $_GET, 'function', null ) == 'savevalue' ) && $this->canAjax( $field, $user, 'html', $reason, true ) ) { $field->set( '_noAjax', true ); if ( in_array( $field->get( 'name' ), array ( 'firstname', 'middlename', 'lastname' ) ) ) { if ( $field->get( 'name' ) != 'firstname' ) { $postdata['firstname'] = $user->get( 'firstname' ); } if ( $field->get( 'name' ) != 'middlename' ) { $postdata['middlename'] = $user->get( 'middlename' ); } if ( $field->get( 'name' ) != 'lastname' ) { $postdata['lastname'] = $user->get( 'lastname' ); } } $_PLUGINS->callField( $field->get( 'type' ), 'fieldClass', array( &$field, &$user, &$postdata, $reason ), $field ); $oldUserComplete = new UserTable( $_CB_database ); foreach ( array_keys( get_object_vars( $user ) ) as $k ) { if ( substr( $k, 0, 1 ) != '_' ) { $oldUserComplete->set( $k, $user->get( $k ) ); } } $orgValue = $user->get( $field->get( 'name' ) ); $_PLUGINS->callField( $field->get( 'type' ), 'prepareFieldDataSave', array( &$field, &$user, &$postdata, $reason ), $field ); $store = false; if ( ! count( $_PLUGINS->getErrorMSG( false ) ) ) { $_PLUGINS->callField( $field->get( 'type' ), 'commitFieldDataSave', array( &$field, &$user, &$postdata, $reason ), $field ); if ( ! count( $_PLUGINS->getErrorMSG( false ) ) ) { if ( $_CB_framework->myId() == $user->get( 'id' ) ) { $user->set( 'lastupdatedate', $_CB_framework->getUTCDate() ); } $_PLUGINS->trigger( 'onBeforeUserUpdate', array( &$user, &$user, &$oldUserComplete, &$oldUserComplete ) ); $clearTextPassword = null; if ( $field->get( 'name' ) == 'password' ) { $clearTextPassword = $user->get( 'password' ); $user->set( 'password', $user->hashAndSaltPassword( $clearTextPassword ) ); } $store = $user->store(); if ( $clearTextPassword ) { $user->set( 'password', $clearTextPassword ); } $_PLUGINS->trigger( 'onAfterUserUpdate', array( &$user, &$user, $oldUserComplete ) ); } else { $_PLUGINS->callField( $field->get( 'type' ), 'rollbackFieldDataSave', array( &$field, &$user, &$postdata, $reason ), $field ); $_PLUGINS->trigger( 'onSaveUserError', array( &$user, $user->getError(), $reason ) ); } } if ( ! $store ) { if ( $orgValue != $user->get( $field->get( 'name' ) ) ) { $user->set( $field->get( 'name' ), $orgValue ); } } $return = null; switch ( $field->get( 'type' ) ) { case 'emailaddress'; $value = $user->get( $field->get( 'name' ) ); if ( $value ) { if ( $ueConfig['allow_email'] == 1 ) { $return .= '<a href="mailto:' . htmlspecialchars( $value ) . '" target="_blank">' . htmlspecialchars( $value ) . '</a>'; } else { $return .= htmlspecialchars( $value ); } } break; case 'primaryemailaddress'; $value = $user->get( $field->get( 'name' ) ); if ( $value && ( $ueConfig['allow_email_display'] != 4 ) ) { switch ( $ueConfig['allow_email_display'] ) { case 1: $return .= htmlspecialchars( $value ); break; case 2: $return .= '<a href="mailto:' . htmlspecialchars( $value ) . '">' . htmlspecialchars( $value ) . '</a>'; break; case 3: $return .= '<a href="' . $_CB_framework->viewUrl( 'emailuser', true, array( 'uid' => (int) $user->get( 'id' ) ) ) . '" title="' . htmlspecialchars( CBTxt::T( 'UE_MENU_SENDUSEREMAIL_DESC', 'Send an Email to this user' ) ) . '">' . CBTxt::T( 'UE_SENDEMAIL', 'Send Email' ) . '</a>'; break; } } break; default: $return .= $_PLUGINS->callField( $field->get( 'type' ), 'getFieldRow', array( &$field, &$user, 'html', 'none', $reason, 0 ), $field ); break; } $placeholder = cbReplaceVars( CBTxt::T( $field->params->get( 'ajax_placeholder' ) ), $user ); $emptyValue = cbReplaceVars( $ueConfig['emptyFieldsText'], $user ); if ( ( ( ! $return ) || ( $return == $emptyValue ) ) && $placeholder ) { $return = $placeholder; } elseif ( ( ! $return ) && ( ! $ueConfig['showEmptyFields'] ) ) { $return = $emptyValue; } $error = $this->getFieldAjaxError( $field, $user, $reason ); $return = ( $error ? '<div class="alert alert-danger">' . $error . '</div>' : null ) . $return; $field->set( '_noAjax', false ); return $return; } return null; }
/** * Sends a PM or Email notification with substitutions based off configuration * * @param int $type 1: Email, 2: PM, 3: Moderators, 4: Auto * @param UserTable|int|null $from * @param UserTable|int|string $to * @param string $subject * @param string $body * @param GroupTable $group * @param array $extra * @return bool */ static public function sendNotification( $type, $from, $to, $subject, $body, $group, $extra = array() ) { global $_CB_framework, $_PLUGINS; if ( ( ! $subject ) || ( ! $body ) || ( ! $group->get( 'id' ) ) || ( $group->get( 'published', 1 ) != 1 ) || ( ! $group->category()->get( 'published', 1 ) ) || ( ! $to ) ) { return false; } if ( $from instanceof UserTable ) { $fromUser = $from; } elseif ( is_int( $from ) ) { $fromUser = \CBuser::getUserDataInstance( $from ); } else { $fromUser = null; } if ( $to instanceof UserTable ) { $toUser = $to; } elseif ( is_int( $to ) ) { $toUser = \CBuser::getUserDataInstance( $to ); } else { $toUser = null; } if ( $fromUser && $toUser && ( $fromUser->get( 'id' ) == $toUser->get( 'id' ) ) ) { return false; } static $plugin = null; static $params = null; if ( ! $params ) { $plugin = $_PLUGINS->getLoadedPlugin( 'user', 'cbgroupjive' ); $params = $_PLUGINS->getPluginParams( $plugin ); } $notifyBy = (int) $params->get( 'notifications_notifyby', 1 ); $fromName = $params->get( 'notifications_from_name', null ); $fromEmail = $params->get( 'notifications_from_address', null ); $cbUser = \CBuser::getInstance( ( $fromUser ? (int) $fromUser->get( 'id' ) : ( $toUser ? (int) $toUser->get( 'id' ) : 0 ) ), false ); $user = $cbUser->getUserData(); $extras = array( 'category_id' => (int) $group->category()->get( 'id' ), 'category_name' => ( $group->category()->get( 'id' ) ? CBTxt::T( $group->category()->get( 'name' ) ) : CBTxt::T( 'Uncategorized' ) ), 'category' => '<a href="' . $_CB_framework->pluginClassUrl( $plugin->element, false, array( 'action' => 'categories', 'func' => 'show', 'id' => (int) $group->get( 'category' ) ) ) . '">' . ( $group->category()->get( 'id' ) ? CBTxt::T( $group->category()->get( 'name' ) ) : CBTxt::T( 'Uncategorized' ) ) . '</a>', 'group_id' => (int) $group->get( 'id' ), 'group_name' => htmlspecialchars( CBTxt::T( $group->get( 'name' ) ) ), 'group' => '<a href="' . $_CB_framework->pluginClassUrl( $plugin->element, false, array( 'action' => 'groups', 'func' => 'show', 'id' => (int) $group->get( 'id' ) ) ) . '">' . htmlspecialchars( CBTxt::T( $group->get( 'name' ) ) ) . '</a>', 'user' => '<a href="' . $_CB_framework->viewUrl( 'userprofile', false, array( 'user' => (int) $user->get( 'id' ) ) ) . '">' . getNameFormat( $user->get( 'name' ), $user->get( 'username' ), Application::Config()->get( 'name_format', 3 ) ) . '</a>' ); if ( ! $toUser ) { $extras['email'] = $to; $extras['name'] = $to; $extras['username'] = $to; } $extras = array_merge( $extras, $extra ); $subject = $cbUser->replaceUserVars( $subject, true, false, $extras, false ); $body = $cbUser->replaceUserVars( $body, false, false, $extras, false ); if ( $type == 4 ) { $type = ( $notifyBy == 2 ? 2 : 1 ); } $notification = new \cbNotification(); if ( $type == 3 ) { // Moderator Notification: $notification->sendToModerators( $subject, $body, false, 1 ); } elseif ( ( $type == 2 ) && $toUser ) { // PM Notification: if ( ! $toUser->get( 'id' ) ) { return false; } $notification->sendUserPMSmsg( $toUser, 0, $subject, $body, true, false, 1, $extras ); } else { // Email Notification: if ( $toUser ) { if ( ! $toUser->get( 'id' ) ) { return false; } $notification->sendFromSystem( $toUser, $subject, $body, 1, 1, null, null, null, $extras, true, $fromName, $fromEmail ); } else { $userTo = new UserTable(); $userTo->set( 'email', $to ); $userTo->set( 'name', $to ); $userTo->set( 'username', $to ); $notification->sendFromSystem( $userTo, $subject, $body, 1, 1, null, null, null, $extras, true, $fromName, $fromEmail ); } } return true; }
/** * Maps profile fields to the user * * @param UserTable $user * @param Hybrid_User_Profile $profile */ private function fields( &$user, $profile ) { foreach ( $this->params->subTree( $this->_provider . '_fields' ) as $field ) { /** @var ParamsInterface $field */ $fromField = $field->get( 'from', null, GetterInterface::STRING ); $toField = $field->get( 'to', null, GetterInterface::STRING ); if ( $fromField && $toField && isset( $profile->$fromField ) ) { if ( ( ! is_array( $profile->$fromField ) ) && ( ! is_object( $profile->$fromField ) ) ) { $user->set( $toField, $profile->$fromField ); } } } }
/** * Direct access to field for custom operations, like for Ajax * * WARNING: direct unchecked access, except if $user is set, then check well for the $reason ... * * @param FieldTable $field * @param UserTable $user * @param array $postdata * @param string $reason 'profile' for user profile view, 'edit' for profile edit, 'register' for registration, 'search' for searches * @return string Expected output. */ public function fieldClass(&$field, &$user, &$postdata, $reason) { global $_CB_framework, $_CB_database, $_PLUGINS; parent::fieldClass($field, $user, $postdata, $reason); // Performs spoof check $myId = (int) $_CB_framework->myId(); $userId = (int) $user->get('id'); $fieldId = (int) $field->get('fieldid'); $ipAddresses = cbGetIParray(); $ipAddress = trim(array_shift($ipAddresses)); $fieldName = $field->get('name'); $readOnly = $this->_isReadOnly($field, $user, $reason); if (cbGetParam($_GET, 'function', null) == 'savevalue' && (!$readOnly && $this->getIncrementAccess($field, $user)) && $userId) { $oldUserComplete = new UserTable($field->getDbo()); foreach (array_keys(get_object_vars($user)) as $k) { if (substr($k, 0, 1) != '_') { $oldUserComplete->set($k, $user->get($k)); } } $direction = stripslashes(cbGetParam($postdata, 'value')); $value = (int) $user->get($fieldName); if ($direction == 'plus') { $increment = (int) $field->params->get('points_inc_plus', 1); $value += $increment && $increment > 0 ? $increment : 0; } elseif ($direction == 'minus') { $increment = (int) $field->params->get('points_inc_minus', 1); $value -= $increment && $increment > 0 ? $increment : 0; $increment = $increment ? -$increment : 0; } else { $increment = 0; } $postdata[$fieldName] = $value; if ($this->validate($field, $user, $fieldName, $value, $postdata, $reason) && $increment && (int) $user->get($fieldName) != $value) { $query = 'INSERT INTO ' . $_CB_database->NameQuote('#__comprofiler_ratings') . "\n (" . $_CB_database->NameQuote('user_id') . ', ' . $_CB_database->NameQuote('type') . ', ' . $_CB_database->NameQuote('item') . ', ' . $_CB_database->NameQuote('target') . ', ' . $_CB_database->NameQuote('rating') . ', ' . $_CB_database->NameQuote('ip_address') . ', ' . $_CB_database->NameQuote('date') . ')' . "\n VALUES (" . $myId . ', ' . $_CB_database->Quote('field') . ', ' . $fieldId . ', ' . $userId . ', ' . (double) $increment . ', ' . $_CB_database->Quote($ipAddress) . ', ' . $_CB_database->Quote($_CB_framework->getUTCDate()) . ')'; $_CB_database->setQuery($query); $_CB_database->query(); $user->set($fieldName, (int) $value); $_PLUGINS->trigger('onBeforeUserUpdate', array(&$user, &$user, &$oldUserComplete, &$oldUserComplete)); $query = 'UPDATE ' . $_CB_database->NameQuote('#__comprofiler') . "\n SET " . $_CB_database->NameQuote($fieldName) . " = " . (int) $user->get($fieldName) . "\n WHERE " . $_CB_database->NameQuote('id') . " = " . $userId; $_CB_database->setQuery($query); if ($_CB_database->query()) { $_PLUGINS->trigger('onAfterUserUpdate', array(&$user, &$user, $oldUserComplete)); } } } return $this->getPointsHTML($field, $user, $reason, true); }
/** * @param cbautoactionsActionTable $trigger * @param UserTable $user */ public function execute( $trigger, $user ) { if ( ! $user->get( 'id' ) ) { if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) { var_dump( CBTxt::T( 'AUTO_ACTION_USERGROUP_NO_USER', ':: Action [action] :: Usergroup skipped due to no user', array( '[action]' => (int) $trigger->get( 'id' ) ) ) ); } return; } $cache = $user->get( 'password' ); $user->set( 'password', null ); foreach ( $trigger->getParams()->subTree( 'usergroup' ) as $row ) { /** @var ParamsInterface $row */ $groups = $row->get( 'groups', null, GetterInterface::STRING ); if ( $groups ) { $groups = explode( '|*|', $groups ); cbArrayToInts( $groups ); } $session = JFactory::getSession(); $jUser = $session->get( 'user' ); $isMe = ( $jUser ? ( $jUser->id == $user->get( 'id' ) ) : false ); switch ( $row->get( 'mode', 'add', GetterInterface::STRING ) ) { case 'create': $title = $trigger->getSubstituteString( $row->get( 'title', null, GetterInterface::STRING ) ); if ( ! $title ) { if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) { var_dump( CBTxt::T( 'AUTO_ACTION_USERGROUP_NO_TITLE', ':: Action [action] :: Usergroup skipped due to missing title', array( '[action]' => (int) $trigger->get( 'id' ) ) ) ); } continue; } $usergroup = JTable::getInstance( 'usergroup' ); $usergroup->load( array( 'title' => $title ) ); if ( ! $usergroup->id ) { $usergroup->parent_id = (int) $row->get( 'parent', 0, GetterInterface::INT ); $usergroup->title = $title; if ( ! $usergroup->store() ) { if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) { var_dump( CBTxt::T( 'AUTO_ACTION_USERGROUP_CREATE_FAILED', ':: Action [action] :: Usergroup failed to create', array( '[action]' => (int) $trigger->get( 'id' ) ) ) ); } continue; } } if ( $row->get( 'add', 1, GetterInterface::BOOLEAN ) ) { if ( ! in_array( $usergroup->id, $user->get( 'gids' ) ) ) { $user->gids[] = $usergroup->id; if ( ! $user->store() ) { if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) { var_dump( CBTxt::T( 'AUTO_ACTION_USERGROUP_FAILED', ':: Action [action] :: Usergroup failed to save. Error: [error]', array( '[action]' => (int) $trigger->get( 'id' ), '[error]' => $user->getError() ) ) ); } continue; } if ( $isMe ) { JAccess::clearStatics(); $session->set( 'user', new JUser( $user->get( 'id' ) ) ); } } } break; case 'replace': if ( ! $groups ) { if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) { var_dump( CBTxt::T( 'AUTO_ACTION_USERGROUP_NO_GROUPS', ':: Action [action] :: Usergroup skipped due to missing groups', array( '[action]' => (int) $trigger->get( 'id' ) ) ) ); } continue; } $user->set( 'gids', $groups ); if ( ! $user->store() ) { if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) { var_dump( CBTxt::T( 'AUTO_ACTION_USERGROUP_FAILED', ':: Action [action] :: Usergroup failed to save. Error: [error]', array( '[action]' => (int) $trigger->get( 'id' ), '[error]' => $user->getError() ) ) ); } continue; } if ( $isMe ) { JAccess::clearStatics(); $session->set( 'user', new JUser( $user->get( 'id' ) ) ); } break; case 'remove': if ( ! $groups ) { if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) { var_dump( CBTxt::T( 'AUTO_ACTION_USERGROUP_NO_GROUPS', ':: Action [action] :: Usergroup skipped due to missing groups', array( '[action]' => (int) $trigger->get( 'id' ) ) ) ); } continue; } $removed = false; foreach( $user->get( 'gids' ) as $k => $gid ) { if ( in_array( $gid, $groups ) ) { unset( $user->gids[$k] ); $removed = true; } } if ( $removed ) { if ( ! $user->store() ) { if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) { var_dump( CBTxt::T( 'AUTO_ACTION_USERGROUP_FAILED', ':: Action [action] :: Usergroup failed to save. Error: [error]', array( '[action]' => (int) $trigger->get( 'id' ), '[error]' => $user->getError() ) ) ); } continue; } if ( $isMe ) { JAccess::clearStatics(); $session->set( 'user', new JUser( $user->get( 'id' ) ) ); } } break; case 'add': default: if ( ! $groups ) { if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) { var_dump( CBTxt::T( 'AUTO_ACTION_USERGROUP_NO_GROUPS', ':: Action [action] :: Usergroup skipped due to missing groups', array( '[action]' => (int) $trigger->get( 'id' ) ) ) ); } continue; } $usergroups = $groups; foreach( $usergroups as $k => $usergroup ) { if ( in_array( $usergroup, $user->get( 'gids' ) ) ) { unset( $usergroups[$k] ); } } if ( $usergroups ) { $user->set( 'gids', array_unique( array_merge( $user->get( 'gids' ), $usergroups ) ) ); if ( ! $user->store() ) { if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) { var_dump( CBTxt::T( 'AUTO_ACTION_USERGROUP_FAILED', ':: Action [action] :: Usergroup failed to save. Error: [error]', array( '[action]' => (int) $trigger->get( 'id' ), '[error]' => $user->getError() ) ) ); } continue; } if ( $isMe ) { JAccess::clearStatics(); $session->set( 'user', new JUser( $user->get( 'id' ) ) ); } } break; } } $user->set( 'password', $cache ); }
/** * @param UserTable $user * @param CBuser $cbUser * @param FieldTable $field * @param string $reason * @param bool $forceNoPost * @return array|mixed|string */ private function getFieldValue( $user, $cbUser, $field, $reason, $forceNoPost = false ) { global $_PLUGINS; static $values = array(); $fieldId = (int) $field->get( 'fieldid' ); $userId = (int) $user->get( 'id' ); if ( ! isset( $values[$fieldId][$userId][$reason][$forceNoPost] ) ) { if ( ! ( $field->params instanceof ParamsInterface ) ) { $field->params = new Registry( $field->params ); } $fieldValue = null; $values[$fieldId][$userId][$reason][$forceNoPost] = $fieldValue; $post = $this->getInput()->getNamespaceRegistry( 'post' ); if ( ( ! $forceNoPost ) && in_array( $reason, array( 'register', 'edit' ) ) && ( $post->count() && in_array( $this->input( 'view', null, GetterInterface::STRING ), array( 'saveregisters', 'saveuseredit' ) ) ) ) { $postUser = new UserTable(); foreach ( array_keys( get_object_vars( $user ) ) as $k ) { if ( substr( $k, 0, 1 ) != '_' ) { $postUser->set( $k, $user->get( $k ) ); } } if ( ! $post->get( $field->get( 'name' ) ) ) { $post->set( $field->get( 'name' ), null ); } $postUser->bindThisUserFromDbArray( $post->asArray() ); $fieldValue = $postUser->get( $field->get( 'name' ) ); if ( is_array( $fieldValue ) ) { $fieldValue = implode( '|*|', $fieldValue ); } if ( $fieldValue === null ) { $field->set( '_noCondition', true ); $fieldValue = $_PLUGINS->callField( $field->get( 'type' ), 'getFieldRow', array( &$field, &$postUser, 'php', 'none', 'profile', 0 ), $field ); $field->set( '_noCondition', false ); if ( is_array( $fieldValue ) ) { $fieldValue = array_shift( $fieldValue ); if ( is_array( $fieldValue ) ) { $fieldValue = implode( '|*|', $fieldValue ); } } if ( $fieldValue === null ) { $fieldValue = $this->getFieldValue( $user, $cbUser, $field, $reason, true ); } } } else { $fieldValue = $user->get( $field->get( 'name' ) ); if ( is_array( $fieldValue ) ) { $fieldValue = implode( '|*|', $fieldValue ); } if ( $fieldValue === null ) { $field->set( '_noCondition', true ); $fieldValue = $_PLUGINS->callField( $field->get( 'type' ), 'getFieldRow', array( &$field, &$user, 'php', 'none', 'profile', 0 ), $field ); $field->set( '_noCondition', false ); if ( is_array( $fieldValue ) ) { $fieldValue = array_shift( $fieldValue ); if ( is_array( $fieldValue ) ) { $fieldValue = implode( '|*|', $fieldValue ); } } } } $values[$fieldId][$userId][$reason][$forceNoPost] = $fieldValue; } return $values[$fieldId][$userId][$reason][$forceNoPost]; }
/** * Store an array of values to user object * Used only in banUser function in FE: TODO: Change usage in banUser ? * * @param $values * @param bool $triggers * @return bool */ public function storeDatabaseValues($values, $triggers = true) { global $_CB_framework, $_PLUGINS; if ($this->id && is_array($values) && $values) { $ui = $_CB_framework->getUi(); $userVars = array_keys(get_object_vars($this)); $user = new UserTable($this->_db); $oldUserComplete = new UserTable($this->_db); foreach ($userVars as $k) { if (substr($k, 0, 1) != '_') { $user->set($k, $this->get($k)); $oldUserComplete->set($k, $this->get($k)); } } foreach ($values as $name => $value) { if (in_array($name, $userVars)) { $user->set($name, $value); } } if ($triggers) { if ($ui == 1) { $_PLUGINS->trigger('onBeforeUserUpdate', array(&$user, &$user, &$oldUserComplete, &$oldUserComplete)); } elseif ($ui == 2) { $_PLUGINS->trigger('onBeforeUpdateUser', array(&$user, &$user, &$oldUserComplete)); } } if (isset($values['password'])) { $clearTextPassword = $user->get('password'); $user->set('password', $this->hashAndSaltPassword($clearTextPassword)); } else { $clearTextPassword = null; $user->set('password', null); } $return = $user->store(); if ($clearTextPassword) { $user->set('password', $clearTextPassword); } if ($triggers) { if ($return) { if ($ui == 1) { $_PLUGINS->trigger('onAfterUserUpdate', array(&$user, &$user, $oldUserComplete)); } elseif ($ui == 2) { $_PLUGINS->trigger('onAfterUpdateUser', array(&$user, &$user, $oldUserComplete)); } } } $error = $user->getError(); if ($error) { $this->set('_error', $error); } unset($user, $oldUserComplete); return $return; } return false; }
/** * @param cbautoactionsActionTable $trigger * @param UserTable $user */ public function execute( $trigger, $user ) { global $_CB_framework, $_PLUGINS, $ueConfig; $params = $trigger->getParams()->subTree( 'registration' ); $approve = (int) $params->get( 'approve', null, GetterInterface::INT ); $confirm = (int) $params->get( 'confirm', null, GetterInterface::INT ); $approval = ( $approve == 2 ? $ueConfig['reg_admin_approval'] : $approve ); $confirmation = ( $confirm == 2 ? $ueConfig['reg_confirmation'] : $confirm ); $usergroup = $params->get( 'usergroup', null, GetterInterface::STRING ); $password = $trigger->getSubstituteString( $params->get( 'password', null, GetterInterface::STRING ) ); $name = array(); if ( ! $usergroup ) { $gids = array( $_CB_framework->getCfg( 'new_usertype' ) ); } else { $gids = explode( '|*|', $usergroup ); } cbArrayToInts( $gids ); $newUser = new UserTable(); $newUser->set( 'gids', $gids ); $newUser->set( 'sendEmail', 0 ); $newUser->set( 'registerDate', $_CB_framework->getUTCDate() ); $newUser->set( 'username', $trigger->getSubstituteString( $params->get( 'username', null, GetterInterface::STRING ) ) ); $newUser->set( 'firstname', $trigger->getSubstituteString( $params->get( 'firstname', null, GetterInterface::STRING ) ) ); $newUser->set( 'middlename', $trigger->getSubstituteString( $params->get( 'middlename', null, GetterInterface::STRING ) ) ); $newUser->set( 'lastname', $trigger->getSubstituteString( $params->get( 'lastname', null, GetterInterface::STRING ) ) ); if ( $newUser->get( 'firstname' ) ) { $name[] = $newUser->get( 'firstname' ); } if ( $newUser->get( 'middlename' ) ) { $name[] = $newUser->get( 'middlename' ); } if ( $newUser->get( 'lastname' ) ) { $name[] = $newUser->get( 'lastname' ); } $newUser->set( 'name', implode( ' ', $name ) ); $newUser->set( 'email', $trigger->getSubstituteString( $params->get( 'email', null, GetterInterface::STRING ) ) ); if ( $password ) { $newUser->set( 'password', $newUser->hashAndSaltPassword( $password ) ); } else { $newUser->setRandomPassword(); $newUser->set( 'password', $newUser->hashAndSaltPassword( $newUser->get( 'password' ) ) ); } $newUser->set( 'registeripaddr', cbGetIPlist() ); if ( $approval == 0 ) { $newUser->set( 'approved', 1 ); } else { $newUser->set( 'approved', 0 ); } if ( $confirmation == 0 ) { $newUser->set( 'confirmed', 1 ); } else { $newUser->set( 'confirmed', 0 ); } if ( ( $newUser->get( 'confirmed' ) == 1 ) && ( $newUser->get( 'approved' ) == 1 ) ) { $newUser->set( 'block', 0 ); } else { $newUser->set( 'block', 1 ); } foreach ( $params->subTree( 'fields' ) as $row ) { /** @var ParamsInterface $row */ $field = $row->get( 'field', null, GetterInterface::STRING ); if ( $field ) { $newUser->set( $field, $trigger->getSubstituteString( $row->get( 'value', null, GetterInterface::RAW ), false, $row->get( 'translate', false, GetterInterface::BOOLEAN ) ) ); } } $_PLUGINS->trigger( 'onBeforeUserRegistration', array( &$newUser, &$newUser ) ); if ( ! $newUser->store() ) { if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) { var_dump( CBTxt::T( 'AUTO_ACTION_REGISTRATION_FAILED', ':: Action [action] :: Registration failed to save. Error: [error]', array( '[action]' => (int) $trigger->get( 'id' ), '[error]' => $newUser->getError() ) ) ); } return; } if ( ( $newUser->get( 'confirmed' ) == 0 ) && ( $confirmation != 0 ) ) { if ( ! $newUser->store() ) { if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) { var_dump( CBTxt::T( 'AUTO_ACTION_REGISTRATION_FAILED', ':: Action [action] :: Registration failed to save. Error: [error]', array( '[action]' => (int) $trigger->get( 'id' ), '[error]' => $newUser->getError() ) ) ); } return; } } if ( $params->get( 'supress', 1, GetterInterface::BOOLEAN ) ) { $emails = false; } else { $emails = true; } activateUser( $newUser, 1, 'UserRegistration', $emails, $emails ); $_PLUGINS->trigger( 'onAfterUserRegistration', array( &$newUser, &$newUser, true ) ); }
/** * @param FieldTable $field * @param UserTable $user * @param string $output * @param string $reason * @param int $list_compare_types * @return mixed */ public function getField( &$field, &$user, $output, $reason, $list_compare_types ) { if ( ( $reason == 'register' ) && ( $output == 'htmledit' ) ) { $code = cbGetParam( $_GET, 'invite_code' ); if ( $code ) { $user->set( 'invite_code', $code ); } } $field->set( 'type', 'text' ); return parent::getField( $field, $user, $output, $reason, $list_compare_types ); }