/** * Registers a new user * * @param UserTable $user * @param Hybrid_User_Profile $profile * @return bool */ private function register( $user, $profile ) { global $_CB_framework, $_PLUGINS, $ueConfig; if ( ! $profile->identifier ) { cbRedirect( $this->_returnUrl, CBTxt::T( 'PROVIDER_PROFILE_MISSING', '[provider] profile could not be found.', array( '[provider]' => $this->_providerName ) ), 'error' ); return false; } $mode = $this->params->get( $this->_provider . '_mode', 1, GetterInterface::INT ); $approve = $this->params->get( $this->_provider . '_approve', 0, GetterInterface::INT ); $confirm = $this->params->get( $this->_provider . '_confirm', 0, GetterInterface::INT ); $usergroup = $this->params->get( $this->_provider . '_usergroup', null, GetterInterface::STRING ); $approval = ( $approve == 2 ? $ueConfig['reg_admin_approval'] : $approve ); $confirmation = ( $confirm == 2 ? $ueConfig['reg_confirmation'] : $confirm ); $usernameFormat = $this->params->get( $this->_provider . '_username', null, GetterInterface::STRING ); $username = null; $dummyUser = new UserTable(); if ( $usernameFormat ) { $extras = array( 'provider' => $this->_provider, 'provider_id' => $this->_providerId, 'provider_name' => $this->_providerName ); foreach ( (array) $profile as $k => $v ) { if ( ( ! is_array( $v ) ) && ( ! is_object( $v ) ) ) { $k = 'profile_' . $k; $extras[$k] = $v; } } $username = preg_replace( '/[<>\\\\"%();&\']+/', '', trim( cbReplaceVars( $usernameFormat, $user, true, false, $extras, false ) ) ); } else { if ( isset( $profile->username ) ) { $username = preg_replace( '/[<>\\\\"%();&\']+/', '', trim( $profile->username ) ); } if ( ( ! $username ) || ( $username && $dummyUser->loadByUsername( $username ) ) ) { $username = preg_replace( '/[<>\\\\"%();&\']+/', '', trim( $profile->displayName ) ); } } if ( ( ! $username ) || ( $username && $dummyUser->loadByUsername( $username ) ) ) { $username = (string) $profile->identifier; } if ( $mode == 2 ) { $user->set( 'email', $profile->email ); } else { if ( $dummyUser->loadByUsername( $username ) ) { cbRedirect( $this->_returnUrl, CBTxt::T( 'UE_USERNAME_NOT_AVAILABLE', "The username '[username]' is already in use.", array( '[username]' => htmlspecialchars( $username ) ) ), 'error' ); return false; } if ( ! $this->email( $user, $profile ) ) { return false; } if ( $dummyUser->loadByEmail( $user->get( 'email' ) ) ) { cbRedirect( $this->_returnUrl, CBTxt::T( 'UE_EMAIL_NOT_AVAILABLE', "The email '[email]' is already in use.", array( '[email]' => htmlspecialchars( $user->get( 'email' ) ) ) ), 'error' ); return false; } $this->avatar( $user, $profile, $mode ); if ( ! $usergroup ) { $gids = array( (int) $_CB_framework->getCfg( 'new_usertype' ) ); } else { $gids = cbToArrayOfInt( explode( '|*|', $usergroup ) ); } $user->set( 'gids', $gids ); $user->set( 'sendEmail', 0 ); $user->set( 'registerDate', $_CB_framework->getUTCDate() ); $user->set( 'password', $user->hashAndSaltPassword( $user->getRandomPassword() ) ); $user->set( 'registeripaddr', cbGetIPlist() ); if ( $approval == 0 ) { $user->set( 'approved', 1 ); } else { $user->set( 'approved', 0 ); } if ( $confirmation == 0 ) { $user->set( 'confirmed', 1 ); } else { $user->set( 'confirmed', 0 ); } if ( ( $user->get( 'confirmed' ) == 1 ) && ( $user->get( 'approved' ) == 1 ) ) { $user->set( 'block', 0 ); } else { $user->set( 'block', 1 ); } } if ( $profile->firstName || $profile->lastName ) { $user->set( 'name', trim( $profile->firstName . ' ' . $profile->lastName ) ); } elseif ( $profile->displayName ) { $user->set( 'name', trim( $profile->displayName ) ); } else { $user->set( 'name', $username ); } switch ( $ueConfig['name_style'] ) { case 2: $lastName = strrpos( $user->get( 'name' ), ' ' ); if ( $lastName !== false ) { $user->set( 'firstname', substr( $user->get( 'name' ), 0, $lastName ) ); $user->set( 'lastname', substr( $user->get( 'name' ), ( $lastName + 1 ) ) ); } else { $user->set( 'firstname', '' ); $user->set( 'lastname', $user->get( 'name' ) ); } break; case 3: $middleName = strpos( $user->get( 'name' ), ' ' ); $lastName = strrpos( $user->get( 'name' ), ' ' ); if ( $lastName !== false ) { $user->set( 'firstname', substr( $user->get( 'name' ), 0, $middleName ) ); $user->set( 'lastname', substr( $user->get( 'name' ), ( $lastName + 1 ) ) ); if ( $middleName !== $lastName ) { $user->set( 'middlename', substr( $user->get( 'name' ), ( $middleName + 1 ), ( $lastName - $middleName - 1 ) ) ); } else { $user->set( 'middlename', '' ); } } else { $user->set( 'firstname', '' ); $user->set( 'lastname', $user->get( 'name' ) ); } break; } $user->set( 'username', $username ); $user->set( $this->_providerField, $profile->identifier ); $this->fields( $user, $profile, $mode ); if ( $mode == 2 ) { foreach ( $user as $k => $v ) { $_POST[$k] = $v; } $emailPass = ( isset( $ueConfig['emailpass'] ) ? $ueConfig['emailpass'] : '******' ); $regErrorMSG = null; if ( ( ( $_CB_framework->getCfg( 'allowUserRegistration' ) == '0' ) && ( ( ! isset( $ueConfig['reg_admin_allowcbregistration'] ) ) || $ueConfig['reg_admin_allowcbregistration'] != '1' ) ) ) { $msg = CBTxt::T( 'UE_NOT_AUTHORIZED', 'You are not authorized to view this page!' ); } else { $msg = null; } $_PLUGINS->loadPluginGroup( 'user' ); $_PLUGINS->trigger( 'onBeforeRegisterFormRequest', array( &$msg, $emailPass, &$regErrorMSG ) ); if ( $msg ) { $_CB_framework->enqueueMessage( $msg, 'error' ); return false; } $fieldsQuery = null; $results = $_PLUGINS->trigger( 'onBeforeRegisterForm', array( 'com_comprofiler', $emailPass, &$regErrorMSG, $fieldsQuery ) ); if ( $_PLUGINS->is_errors() ) { $_CB_framework->enqueueMessage( $_PLUGINS->getErrorMSG( '<br />' ), 'error' ); return false; } if ( implode( '', $results ) != '' ) { $return = '<div class="cb_template cb_template_' . selectTemplate( 'dir' ) . '">' . '<div>' . implode( '</div><div>', $results ) . '</div>' . '</div>'; echo $return; return false; } $_CB_framework->enqueueMessage( CBTxt::T( 'PROVIDER_SIGN_UP_INCOMPLETE', 'Your [provider] sign up is incomplete. Please complete the following.', array( '[provider]' => $this->_providerName ) ) ); HTML_comprofiler::registerForm( 'com_comprofiler', $emailPass, $user, $_POST, $regErrorMSG ); return false; } else { $_PLUGINS->trigger( 'onBeforeUserRegistration', array( &$user, &$user ) ); if ( $user->store() ) { if ( $user->get( 'confirmed' ) == 0 ) { $user->store(); } $messagesToUser = activateUser( $user, 1, 'UserRegistration' ); $_PLUGINS->trigger( 'onAfterUserRegistration', array( &$user, &$user, true ) ); if ( $user->get( 'block' ) == 1 ) { $return = '<div class="cb_template cb_template_' . selectTemplate( 'dir' ) . '">' . '<div>' . implode( '</div><div>', $messagesToUser ) . '</div>' . '</div>'; echo $return; } else { return true; } } cbRedirect( $this->_returnUrl, CBTxt::T( 'SIGN_UP_WITH_PROVIDER_FAILED', 'Sign up with [provider] failed. Error: [error]', array( '[provider]' => $this->_providerName, '[error]' => $user->getError() ) ), 'error' ); return false; } }
/** * Get authorized Access Levels (STRICTLY int and STRICTLY unique ids) for this user * * @since 1.8 * * @param boolean $cb1xNumbering DEFAULT: FALSE: (if $cb1xNumbering with CB 1.x's definition for standard levels 0,1,2) * @return array of int STRICTLY int and STRICTLY unique ids */ public function getAuthorisedViewLevelsIds($cb1xNumbering = false) { global $_CB_framework; if ($this->_cbuser->id && $this->_cbuser->id != $_CB_framework->myId()) { $userId = (int) $this->_cbuser->id; } else { $userId = null; } if (checkJversion() >= 2) { $user = JFactory::getUser($userId); $cmsAccess = array_unique(cbToArrayOfInt($user->getAuthorisedViewLevels())); // Keep backwards levels compatible: J1.6's 1 is CB's 0, 2 is 1, 3 is 2: if ($cb1xNumbering) { foreach ($cmsAccess as $k => $v) { if ($v <= 3) { --$cmsAccess[$k]; } } } } else { $cmsAccess = $_CB_framework->acl->get_object_access($userId, true, $cb1xNumbering); if ($cmsAccess) { cbArrayToInts($cmsAccess); } else { $cmsAccess = array(0); } } return $cmsAccess; }
/** * prepare GroupJive Itemid if not found return CB Itemid * * @param boolean $htmlspecialchars * @param string $task * @return string */ static public function getItemid( $htmlspecialchars = false, $task = null ) { global $_CB_framework, $_CB_database; static $Itemid = array(); if ( ! isset( $Itemid[$task] ) ) { $plugin = cbgjClass::getPlugin(); $generalItemid = $plugin->params->get( 'general_itemid', null ); $url = 'index.php?option=com_comprofiler&task=pluginclass&plugin=cbgroupjive'; if ( $task ) { $url .= $task; } $url .= '%'; if ( ( ! $generalItemid ) || $task ) { $query = 'SELECT ' . $_CB_database->NameQuote( 'id' ) . "\n FROM " . $_CB_database->NameQuote( '#__menu' ) . "\n WHERE " . $_CB_database->NameQuote( 'link' ) . " LIKE " . $_CB_database->Quote( $url ) . "\n AND " . $_CB_database->NameQuote( 'published' ) . " = 1" . "\n AND " . $_CB_database->NameQuote( 'access' ) . " IN ( " . implode( ',', cbToArrayOfInt( CBuser::getMyInstance()->getAuthorisedViewLevelsIds( ( checkJversion() >= 2 ? false : true ) ) ) ) . " )" . ( checkJversion() >= 2 ? "\n AND " . $_CB_database->NameQuote( 'language' ) . " IN ( " . $_CB_database->Quote( $_CB_framework->getCfg( 'lang_tag' ) ) . ", '*', '' )" : null ); $_CB_database->setQuery( $query ); $Itemid[$task] = $_CB_database->loadResult(); if ( ( ! $Itemid[$task] ) && $task ) { $Itemid[$task] = cbgjClass::getItemid( 0 ); } elseif ( ! $Itemid[$task] ) { $Itemid[$task] = getCBprofileItemid( null ); } } else { $Itemid[$task] = $generalItemid; } } if ( is_bool( $htmlspecialchars ) ) { return ( $htmlspecialchars ? '&' : '&' ) . 'Itemid=' . $Itemid[$task]; } else { return $Itemid[$task]; } }
/** * @param null|string|int|FieldTable[] $fields * @param string $reason * @param int $userId * @param bool $jquery * @return stdClass */ private function getFieldConditional( $fields, $reason, $userId, $jquery = false ) { global $_CB_framework; $condition = new stdClass(); $condition->show = array(); $condition->hide = array(); static $userCache = array(); if ( ! isset( $userCache[$userId] ) ) { $cbUser = CBuser::getInstance( (int) $userId, false ); $cmsUser = Application::User( (int) $userId ); $userCache[$userId] = array( $cbUser, $cbUser->getUserData(), $cmsUser->getAuthorisedViewLevels(), $cmsUser->getAuthorisedGroups() ); } /** @var CBuser $cbUser */ $cbUser = $userCache[$userId][0]; /** @var UserTable $user */ $user = $userCache[$userId][1]; /** @var array $userAccessLevels */ $userAccessLevels = $userCache[$userId][2]; /** @var array $userUsergroups */ $userUsergroups = $userCache[$userId][3]; static $fieldCache = array(); if ( ! $fields ) { /** @var FieldTable[] $tabsCache */ static $tabsCache = array(); if ( ! isset( $tabsCache[$user->id] ) ) { $cbTabs = $cbUser->_getCbTabs(); $tabsCache[$user->id] = $cbTabs->_getTabFieldsDb( null, $user, 'adminfulllist', null, true, true ); } $fields = $tabsCache[$user->id]; } elseif ( ! is_array( $fields ) ) { if ( is_string( $fields ) || is_integer( $fields ) ) { $fieldId = (int) $fields; if ( $fieldId ) { if ( ! isset( $fieldCache[$fieldId] ) ) { $field = new FieldTable(); $field->load( $fieldId ); $fieldCache[$fieldId] = $field; } $fields = $fieldCache[$fieldId]; } } $fields = array( $fields ); } elseif ( is_array( $fields ) ) { $fieldArray = array(); foreach ( $fields as $fieldId ) { if ( is_string( $fieldId ) || is_integer( $fieldId ) ) { $fieldId = (int) $fieldId; if ( $fieldId ) { if ( ! isset( $fieldCache[$fieldId] ) ) { $field = new FieldTable(); $field->load( $fieldId ); $fieldCache[$fieldId] = $field; } $fieldArray[] = $fieldCache[$fieldId]; } } elseif ( $fieldId instanceof FieldTable ) { $fieldArray[] = $fieldId; } } $fields = $fieldArray; } /** @var Registry[] $fieldParams */ static $fieldParams = array(); /** @var array[] $conditioned */ static $conditioned = array(); $uId = (int) $user->get( 'id' ); if ( $fields ) foreach ( $fields as $field ) { if ( $field instanceof FieldTable ) { $fId = (int) $field->get( 'fieldid' ); if ( ! isset( $conditioned[$fId][$uId][$reason][$jquery] ) ) { $fieldConditions = array(); $conditioned[$fId][$uId][$reason][$jquery] = $fieldConditions; if ( ! isset( $fieldParams[$fId] ) ) { if ( ! ( $field->params instanceof ParamsInterface ) ) { $field->params = new Registry( $field->params ); } $fieldParams[$fId] = $field->params; } $params = $fieldParams[$fId]; for ( $i = 1; $i <= 5; $i++ ) { $conditional = ( $i > 1 ? $i : null ); $display = (int) $params->get( 'cbconditional_display' . $conditional, 0 ); if ( $reason == 'register' ) { if ( ! $params->get( 'cbconditional_target_reg' . $conditional, 1 ) ) { $display = 0; } } elseif ( $reason == 'edit' ) { if ( ! $params->get( 'cbconditional_target_edit' . $conditional, 1 ) ) { $display = 0; } } elseif ( $reason == 'profile' ) { if ( ! $params->get( 'cbconditional_target_view' . $conditional, 1 ) ) { $display = 0; } } elseif ( $reason == 'search' ) { if ( ! $params->get( 'cbconditional_target_search' . $conditional, 0 ) ) { $display = 0; } } elseif ( $reason == 'list' ) { if ( ! $params->get( 'cbconditional_target_list' . $conditional, 1 ) ) { $display = 0; } } if ( $display ) { if ( $display == 2 ) { $mode = (int) $params->get( 'cbconditional_mode' . $conditional, 0 ); $show = $this->getFieldsArray( ( $mode == 1 ? $fId : null ) ); $hide = $this->getFieldsArray( ( $mode == 0 ? $fId : null ) ); $optshow = array(); $opthide = array(); $fieldPair = explode( ',', $params->get( 'cbconditional_field' . $conditional, null ) ); if ( count( $fieldPair ) < 2 ) { array_unshift( $fieldPair, 0 ); } $fieldId = (int) array_shift( $fieldPair ); $fieldName = array_pop( $fieldPair ); if ( ! isset( $fields[$fieldId] ) ) { $field = new FieldTable(); $field->load( $fieldId ); $fields[$fieldId] = $field; } $fieldObj = $fields[$fieldId]; } else { $show = $this->getFieldsArray( $params->get( 'cbconditional_show' . $conditional, null ) ); $hide = $this->getFieldsArray( $params->get( 'cbconditional_hide' . $conditional, null ) ); $optshow = $this->getFieldsArray( $params->get( 'cbconditional_options_show' . $conditional, null ) ); $opthide = $this->getFieldsArray( $params->get( 'cbconditional_options_hide' . $conditional, null ) ); $fieldId = (int) $field->get( 'fieldid' ); $fieldName = $field->get( 'name' ); $fieldObj = $field; } if ( $show || $hide || $optshow || $opthide ) { $operator = (int) $params->get( 'cbconditional_operator' . $conditional, 0 ); $value = $cbUser->replaceUserVars( $params->get( 'cbconditional_value' . $conditional, null ), false, true, $this->getExtras(), ( (int) $params->get( 'cbconditional_value_translate' . $conditional, 0 ) ? true : false ) ); if ( in_array( $operator, array( 6, 7 ) ) ) { $value = null; } switch ( $fieldName ) { case 'customvalue': $fieldValue = $cbUser->replaceUserVars( $params->get( 'cbconditional_customvalue' . $conditional, null ), false, true, $this->getExtras(), ( (int) $params->get( 'cbconditional_customvalue_translate' . $conditional, 0 ) ? true : false ) ); break; case 'customviewaccesslevels': $accessLevels = cbToArrayOfInt( explode( '|*|', $params->get( 'cbconditional_customviewaccesslevels' . $conditional, null ) ) ); $fieldValue = 0; foreach ( $accessLevels as $accessLevel ) { if ( in_array( $accessLevel, $userAccessLevels ) ) { $fieldValue = 1; break; } } $operator = 0; $value = 1; break; case 'customusergroups': $userGroups = cbToArrayOfInt( explode( '|*|', $params->get( 'cbconditional_customusergroups' . $conditional, null ) ) ); $fieldValue = 0; foreach ( $userGroups as $userGroup ) { if ( in_array( $userGroup, $userUsergroups ) ) { $fieldValue = 1; break; } } $operator = 0; $value = 1; break; default: $fieldValue = $this->getFieldValue( $user, $cbUser, $fieldObj, $reason ); break; } if ( $jquery ) { $_CB_framework->addJQueryPlugin( 'cbcondition', '/components/com_comprofiler/plugin/user/plug_cbconditional/js/cbcondition.js' ); $js = "var conditionShow = [];" . "var conditionHide = [];"; foreach ( $show as $v ) { $js .= "conditionShow.push( '#cbfr_$v,#cbfr_" . $v . "__verify,#cbfrd_$v,#cbfrd_" . $v . "__verify' );"; } foreach ( $hide as $k => $v ) { $js .= "conditionHide.push( '#cbfr_$v,#cbfr_" . $v . "__verify,#cbfrd_$v,#cbfrd_" . $v . "__verify' );"; } foreach ( $optshow as $k => $v ) { $js .= "conditionShow.push( '#cbf$v' );"; } foreach ( $opthide as $k => $v ) { $js .= "conditionHide.push( '#cbf$v' );"; } switch ( $fieldName ) { case 'customvalue': case 'customviewaccesslevels': case 'customusergroups': $js .= "$.cbcondition({" . "conditions: [{" . "operator: " . (int) $operator . "," . "input: '" . addslashes( str_replace( array( "\n", "\r" ), array( "\\n", "\\r" ), ( is_array( $fieldValue ) ? implode( '|*|', $fieldValue ) : $fieldValue ) ) ) . "'," . "value: '" . addslashes( str_replace( array( "\n", "\r" ), array( "\\n", "\\r" ), ( is_array( $value ) ? implode( '|*|', $value ) : $value ) ) ) . "'," . "show: conditionShow," . "hide: conditionHide," . "reset: " . (int) $this->params->get( 'cond_reset', 0 ) . "" . "}]" . "});"; break; default: $js .= "$( '#cbfr_" . (int) $fieldId . ",#cbfrd_" . (int) $fieldId . "' ).cbcondition({" . "conditions: [{" . "operator: " . (int) $operator . "," . "input: '" . addslashes( str_replace( array( "\n", "\r" ), array( "\\n", "\\r" ), ( is_array( $fieldValue ) ? implode( '|*|', $fieldValue ) : $fieldValue ) ) ) . "'," . "value: '" . addslashes( str_replace( array( "\n", "\r" ), array( "\\n", "\\r" ), ( is_array( $value ) ? implode( '|*|', $value ) : $value ) ) ) . "'," . "show: conditionShow," . "hide: conditionHide," . "reset: " . (int) $this->params->get( 'cond_reset', 0 ) . "" . "}]" . "});"; break; } $_CB_framework->outputCbJQuery( $js, 'cbcondition' ); } $fieldConditions[] = array( 'match' => $this->getMatch( $fieldValue, $operator, $value ), 'show' => $show, 'hide' => $hide ); } } } $conditioned[$fId][$uId][$reason][$jquery] = $fieldConditions; } $conditions = $conditioned[$fId][$uId][$reason][$jquery]; foreach ( $conditions as $cond ) { if ( $cond['match'] ) { foreach ( $cond['show'] as $v ) { $v = (int) $v; if ( in_array( $v, $condition->hide ) ) { unset( $condition->hide[$v] ); } if ( ! in_array( $v, $condition->show ) ) { array_push( $condition->show, $v ); } } foreach ( $cond['hide'] as $v ) { $v = (int) $v; if ( in_array( $v, $condition->show ) ) { unset( $condition->show[$v] ); } if ( ! in_array( $v, $condition->hide ) ) { array_push( $condition->hide, $v ); } } } else { foreach ( $cond['show'] as $v ) { $v = (int) $v; if ( in_array( $v, $condition->show ) ) { unset( $condition->show[$v] ); } if ( ! in_array( $v, $condition->hide ) ) { array_push( $condition->hide, $v ); } } foreach ( $cond['hide'] as $v ) { $v = (int) $v; if ( in_array( $v, $condition->hide ) ) { unset( $condition->hide[$v] ); } if ( ! in_array( $v, $condition->show ) ) { array_push( $condition->show, $v ); } } } } } } return $condition; }
/** * Copy the named array or object content into this object as vars * only existing vars of object are filled. * When undefined in array, object variables are kept. * * WARNING: DOES addslashes / escape BY DEFAULT * * Can be overridden or overloaded. * * @param array|object $array The input array or object * @param string $ignore Fields to ignore * @param string $prefix Prefix for the array keys * @return boolean TRUE: ok, FALSE: error on array binding */ public function bind($array, $ignore = '', $prefix = null) { $bind = parent::bind($array, $ignore, $prefix); if ($bind) { if ($this->gids !== null && is_string($this->gids) && strlen($this->gids) > 0) { if ($this->gids[0] === '{' || $this->gids[0] === '[') { $gids = json_decode($this->gids); } else { $gids = explode('|*|', $this->gids); } $this->gids = cbToArrayOfInt($gids); } } return $bind; }
/** * @param UserTable $user * @param null|int $fieldId * @return bool */ static public function checkProfileDisplayAccess( $user, $fieldId = null ) { if ( self::checkUserModerator() ) { return true; } static $field = null; static $rows = array(); static $cache = array(); $myId = Application::MyUser()->getUserId(); $userId = (int) $user->get( 'id' ); $fieldId = (int) $fieldId; if ( ! isset( $cache[$userId][$myId][$fieldId] ) ) { $authorized = true; if ( ! $field ) { $field = new FieldTable(); $field->load( array( 'name' => 'privacy_profile', 'published' => 1 ) ); } if ( ! ( $field->params instanceof ParamsInterface ) ) { $field->params = new Registry( $field->params ); } $hideFields = cbToArrayOfInt( explode( '|*|', $field->params->get( 'cbprivacy_profile_fields', null ) ) ); if ( ( $fieldId && in_array( $fieldId, $hideFields ) ) || ( ! $fieldId ) ) { if ( ! isset( $rows[$userId] ) ) { $row = new cbprivacyPrivacyTable(); $query = 'SELECT *' . "\n FROM " . $row->getDbo()->NameQuote( $row->getTableName() ) . "\n WHERE " . $row->getDbo()->NameQuote( 'user_id' ) . " = " . (int) $userId . "\n AND " . $row->getDbo()->NameQuote( 'type' ) . " = " . $row->getDbo()->Quote( 'profile' ) . "\n AND ( " . $row->getDbo()->NameQuote( 'subtype' ) . " IS NULL OR " . $row->getDbo()->NameQuote( 'subtype' ) . " = " . $row->getDbo()->Quote( '' ) . " )"; $row->getDbo()->setQuery( $query, 0, 1 ); $row->getDbo()->loadObject( $row ); $rows[$userId] = $row; } /** @var cbprivacyPrivacyTable $privacy */ $privacy = $rows[$userId]; $rule = $privacy->get( 'rule', $field->params->get( 'cbprivacy_profile_default', '0' ) ); if ( $rule != '0' ) { if ( ! $privacy->get( 'id' ) ) { $privacy->set( 'user_id', (int) $userId ); $privacy->set( 'rule', $rule ); } if ( ! $privacy->isAuthorized( $myId ) ) { $authorized = false; } } } $cache[$userId][$myId][$fieldId] = $authorized; } return $cache[$userId][$myId][$fieldId]; }
/** * Checks if $userId has anyway access because of his permissions * * @param int $userId * @return int */ public function hasAccessAnyway( $userId ) { global $_CB_framework; // allow access to someone who is unrestricted: $params = cbpaidApp::settingsParams(); $integration_full_access = cbToArrayOfInt( $params->get( 'integration_cpaycontent_access', $_CB_framework->acl->mapGroupNamesToValues( array( 'Administrator', 'Superadministrator' ) ) ) ); if ( $userId ) { $myAclGids = Application::User( (int) $userId )->getAuthorisedGroups( false ); } else { $myAclGids = array( $_CB_framework->acl->mapGroupNamesToValues( 'Public' ) ); } return count( array_intersect( $myAclGids, $integration_full_access ) ); }
/** * returns all the parameters needed for a hyperlink or a menu entry to do a pms action * @param int userId of receiver * @param int userId of sender * @param string subject of PMS message * @param string body of PMS message * @param int kind of link: 1: link to compose new PMS message for $toid user. 2: link to inbox of $fromid user; 3: outbox, 4: trashbox, 5: link to edit pms options * @return mixed array of string {"caption" => menu-text ,"url" => NON-cbSef relative url-link, "tooltip" => description} or false and errorMSG */ function getPMSlink($toid, $fromid, $subject, $message, $kind) { global $_CB_framework, $_CB_database; $params = $this->params; $pmsType = $params->get('pmsType', '1'); if (!$this->_checkPMSinstalled($pmsType)) { return false; } switch ($pmsType) { case 1: //MyPMS OS $rowTo = new moscomprofilerUser($_CB_database); $rowTo->load((int) $toid); $pmsurlBase = "index.php?option=com_pms"; $pmsurlSend = $pmsurlBase . "&page=new&id=" . urlencode($rowTo->username); $pmsurlInbox = $pmsurlBase . "&page=index"; break; case 2: //PMS Pro $rowTo = new moscomprofilerUser($_CB_database); $rowTo->load((int) $toid); $pmsurlBase = "index.php?option=com_mypms"; $pmsurlSend = $pmsurlBase . "&task=new&to=" . urlencode($rowTo->username); $pmsurlInbox = $pmsurlBase . "&task=inbox"; $pmsurlOutbox = $pmsurlBase . "&task=sent"; $pmsurlTrashbox = $pmsurlBase . "&task=trash"; $pmsurlOptions = $pmsurlBase . "&task=editprofile"; break; case 3: //UddeIM 0.4 $pmsurlBase = "index.php?option=com_uddeim"; $pmsurlSend = $pmsurlBase . "&task=new&recip=" . $toid; $pmsurlInbox = $pmsurlBase . "&task=inbox"; $pmsurlOutbox = $pmsurlBase . "&task=outbox"; $pmsurlTrashbox = $pmsurlBase . "&task=trashcan"; break; case 4: //UddeIM 1.0 $pmsurlBase = "index.php?option=com_uddeim"; $pmsurlSend = $pmsurlBase . "&task=new&recip=" . $toid; $pmsurlInbox = $pmsurlBase . "&task=inbox"; $pmsurlOutbox = $pmsurlBase . "&task=outbox"; $pmsurlTrashbox = $pmsurlBase . "&task=trashcan"; $pmsurlOptions = $pmsurlBase . "&task=settings"; break; case 5: //PMS enhanced 2.x by Stefan Klingner $rowTo = new moscomprofilerUser($_CB_database); $rowTo->load((int) $toid); $pmsurlBase = "index.php?option=com_pms"; $pmsurlSend = $pmsurlBase . "&page=new&id=" . urlencode($rowTo->username); $pmsurlInbox = $pmsurlBase . "&page=index"; $pmsurlOutbox = $pmsurlBase . "&page=sent_items"; $pmsurlTrashbox = $pmsurlBase . "&page=trash"; $pmsurlOptions = $pmsurlBase . "&page=settings"; break; case 6: //JIM 1.0.1 $rowTo = new moscomprofilerUser($_CB_database); $rowTo->load((int) $toid); $pmsurlBase = "index.php?option=com_jim"; $pmsurlSend = $pmsurlBase . "&page=new&id=" . urlencode($rowTo->username); $pmsurlInbox = $pmsurlBase . "&page=index"; break; default: $this->_setErrorMSG("Incorrect PMS type"); return false; break; } $query = 'SELECT ' . $_CB_database->NameQuote('id') . "\n FROM " . $_CB_database->NameQuote('#__menu') . "\n WHERE " . $_CB_database->NameQuote('link') . " LIKE " . $_CB_database->Quote($pmsurlBase . '%', false) . "\n AND " . $_CB_database->NameQuote('published') . " = 1" . "\n AND " . $_CB_database->NameQuote('access') . " IN ( " . implode(',', cbToArrayOfInt(CBuser::getMyInstance()->getAuthorisedViewLevelsIds(checkJversion() >= 2 ? false : true))) . " )" . (checkJversion() >= 2 ? "\n AND " . $_CB_database->NameQuote('language') . " IN ( " . $_CB_database->Quote($_CB_framework->getCfg('lang_tag')) . ", '*', '' )" : null); $_CB_database->setQuery($query); $pms_id = $_CB_database->loadResult(); if ($pms_id) { $pmsitemid = "&Itemid=" . $pms_id; } else { $pmsitemid = null; } switch ($kind) { case 1: return array("caption" => $params->get('pmsMenuText', _UE_PM_USER), "url" => $pmsurlSend . $pmsitemid, "tooltip" => $params->get('pmsMenuDesc', _UE_MENU_PM_USER_DESC)); break; case 2: return array("caption" => $params->get('pmsMenuInboxText', _UE_PM_INBOX), "url" => $pmsurlInbox . $pmsitemid, "tooltip" => $params->get('pmsMenuInboxDesc', _UE_MENU_PM_INBOX_DESC)); break; case 3: if ($pmsType != 1 && $pmsType != 6) { return array("caption" => $params->get('pmsMenuOutboxText', _UE_PM_OUTBOX), "url" => $pmsurlOutbox . $pmsitemid, "tooltip" => $params->get('pmsMenuOutboxDesc', _UE_MENU_PM_OUTBOX_DESC)); } break; case 4: if ($pmsType != 1 && $pmsType != 6) { return array("caption" => $params->get('pmsMenuTrashboxText', _UE_PM_TRASHBOX), "url" => $pmsurlTrashbox . $pmsitemid, "tooltip" => $params->get('pmsMenuTrashboxDesc', _UE_MENU_PM_TRASHBOX_DESC)); } break; case 5: if ($pmsType == 2 || $pmsType == 5) { return array("caption" => $params->get('pmsMenuOptionsText', _UE_PM_OPTIONS), "url" => $pmsurlOptions . $pmsitemid, "tooltip" => $params->get('pmsMenuOptionsDesc', _UE_MENU_PM_OPTIONS_DESC)); } break; default: break; } $this->_setErrorMSG("Function not supported by this PMS type"); return false; }