/** * @param string $value * @param string $reason * @param null|FieldTable $field * @param null|UserTable $user * @param boolean $htmlspecialchars * @param array $extra * @return string */ protected function formatFieldValueLayout($value, $reason = 'profile', $field = null, $user = null, $htmlspecialchars = true, $extra = array()) { if (in_array($reason, array('profile', 'list', 'edit', 'register')) && $value !== null && $value !== '' && $field !== null && !$field->get('_hideLayout', 0)) { switch ($reason) { case 'register': $layout = CBTxt::T($field->params->get('fieldLayoutRegister', null)); break; case 'edit': $layout = CBTxt::T($field->params->get('fieldLayoutEdit', null)); break; case 'list': $layout = CBTxt::T($field->params->get('fieldLayoutList', null)); break; case 'profile': default: $layout = CBTxt::T($field->params->get('fieldLayout', null)); break; } // Remove userdata and userfield usage of self from layout to avoid infinite loop: $layout = trim(preg_replace('/\\[cb:(userdata +field|userfield +field)="' . preg_quote($field->get('name')) . '"[^]]+\\]/i', '', $layout)); if ($layout) { $value = str_replace('[value]', $value, $layout); if ($field->params->get('fieldLayoutContentPlugins', 0)) { $value = Application::Cms()->prepareHtmlContentPlugins($value); } if ($user !== null) { $value = cbReplaceVars($value, $user, $htmlspecialchars, true, $extra); } } } return $value; }
/** * @param FieldTable $field * @param UserTable $user * @param array $postdata * @param bool $joined * @return null|string */ private function getValue( $field, $user, $postdata, $joined = false ) { $value = cbGetParam( $postdata, $field->get( 'name' ), null, _CB_ALLOWRAW ); if ( ( $value === null ) || ( $value === '' ) || ( is_array( $value ) && ( count( $value ) <= 0 ) ) ) { $value = ''; } else { $options = $this->getGroups( $field, $user, true, $joined ); $groups = array(); foreach ( $options as $option ) { $groups[] = $option->value; } if ( is_array( $value ) ) { $values = array(); foreach ( $value as $k => $v ) { $v = stripslashes( $v ); if ( in_array( $value, $groups ) ) { $values[] = $v; } } $value = $this->_implodeCBvalues( $values ); } else { $value = stripslashes( $value ); if ( ! in_array( $value, $groups ) ) { $value = null; } } } return $value; }
/** * Commented CBT calls for language parser pickup: Moved to cb.core.php so they get picked-up in front-end language file and not in backend one. */ function loadSampleData() { global $_CB_Backend_Title; @set_time_limit(240); $_CB_Backend_Title = array(0 => array('fa fa-wrench', CBTxt::T('TOOLS_SAMPLE_DATA_TITLE', 'CB Tools: Sample Data: Results'))); $return = null; $affected = false; $tab = new TabTable(); $tab->load(array('title' => '_UE_ADDITIONAL_INFO_HEADER')); if (!$tab->tabid) { $affected = true; $tab->set('title', '_UE_ADDITIONAL_INFO_HEADER'); $tab->set('displaytype', 'menunested'); $tab->set('position', 'canvas_main_middle'); $tab->set('viewaccesslevel', 1); $tab->set('enabled', 1); $tab->set('ordering', 1); if ($tab->getError() || !$tab->store()) { $return .= '<div class="form-group cb_form_line clearfix text-danger">' . CBTxt::T('TOOLS_SAMPLE_DATA_TAB_NOT_OK', 'Tab [title] failed to add. Error: [error]', array('[title]' => $tab->get('title'), '[error]' => $tab->getError())) . '</div>'; } } if ($affected) { $return .= '<div class="form-group cb_form_line clearfix text-success">' . CBTxt::T('TOOLS_SAMPLE_DATA_TAB_OK', 'Tab Added Successfully!') . '</div>'; } $affected = false; $fields = array('cb_website' => array('title' => '_UE_Website', 'type' => 'webaddress', 'registration' => 0, 'ordering' => 1), 'cb_location' => array('title' => '_UE_Location', 'type' => 'text', 'maxlength' => 50, 'size' => 25, 'registration' => 0, 'ordering' => 2), 'cb_occupation' => array('title' => '_UE_Occupation', 'type' => 'text', 'registration' => 0, 'ordering' => 3), 'cb_interests' => array('title' => '_UE_Interests', 'type' => 'text', 'registration' => 0, 'ordering' => 4), 'cb_company' => array('title' => '_UE_Company', 'type' => 'text', 'ordering' => 5), 'cb_city' => array('title' => '_UE_City', 'type' => 'text', 'ordering' => 6), 'cb_state' => array('title' => '_UE_State', 'type' => 'text', 'maxlength' => 10, 'size' => 4, 'ordering' => 7), 'cb_zipcode' => array('title' => '_UE_ZipCode', 'type' => 'text', 'ordering' => 8), 'cb_country' => array('title' => '_UE_Country', 'type' => 'text', 'ordering' => 9), 'cb_address' => array('title' => '_UE_Address', 'type' => 'text', 'ordering' => 10), 'cb_phone' => array('title' => '_UE_PHONE', 'type' => 'text', 'ordering' => 11), 'cb_fax' => array('title' => '_UE_FAX', 'type' => 'text', 'ordering' => 12)); foreach ($fields as $fieldName => $fieldSettings) { $field = new FieldTable(); $field->load(array('name' => $fieldName)); if (!$field->fieldid) { $affected = true; $field->set('name', $fieldName); $field->set('registration', 1); $field->set('profile', 1); $field->set('edit', 1); $field->set('published', 1); foreach ($fieldSettings as $column => $value) { $field->set($column, $value); } $field->set('tabid', $tab->tabid); $field->set('pluginid', 1); if ($field->getError() || !$field->store()) { $return .= '<div class="form-group cb_form_line clearfix text-danger">' . CBTxt::T('TOOLS_SAMPLE_DATA_FIELD_NOT_OK', 'Field [name] failed to add. Error: [error]', array('[name]' => $field->get('name'), '[error]' => $field->getError())) . '</div>'; } } } if ($affected) { $return .= '<div class="form-group cb_form_line clearfix text-success">' . CBTxt::T('TOOLS_SAMPLE_DATA_FIELD_OK', 'Fields Added Successfully!') . '</div>'; } $affected = false; $list = new ListTable(); $list->load(array('title' => 'Members List')); if (!$list->listid) { $affected = true; $list->set('title', 'Members List'); $list->set('viewaccesslevel', 1); $list->set('usergroupids', '1|*|6|*|7|*|2|*|3|*|4|*|5|*|8'); $list->set('default', 1); $list->set('published', 1); $list->set('ordering', 1); $listParams = new Registry(); $listParams->set('sort_mode', '0'); $listParams->set('basic_sort', array(array('column' => 'username', 'direction' => 'ASC'))); $listParams->set('columns', array(array('title' => 'User', 'size' => '3', 'fields' => array(array('field' => '17', 'display' => '4'), array('field' => '29', 'display' => '4'), array('field' => '42', 'display' => '4'), array('field' => '26', 'display' => '4'))), array('title' => 'Info', 'size' => '9', 'fields' => array(array('field' => '27', 'display' => '1'), array('field' => '49', 'display' => '1'), array('field' => '28', 'display' => '1'))))); $listParams->set('list_grid_layout', '1'); $list->set('params', $listParams->asJson()); if ($list->getError() || !$list->store()) { $return .= '<div class="form-group cb_form_line clearfix text-danger">' . CBTxt::T('TOOLS_SAMPLE_DATA_LIST_NOT_OK', 'List [title] failed to add. Error: [error]', array('[title]' => $list->get('title'), '[error]' => $tab->getError())) . '</div>'; } } if ($affected) { $return .= '<div class="form-group cb_form_line clearfix text-success">' . CBTxt::T('TOOLS_SAMPLE_DATA_LIST_OK', 'List Added Successfully!') . '</div>'; } if (!$return) { $return .= '<div class="form-group cb_form_line clearfix">' . CBTxt::T('TOOLS_SAMPLE_DATA_ALREADY_CONFIGURED', 'Sample Data is already loaded!') . '</div>'; } echo $return; }
/** * output points field html display * * @param FieldTable $field * @param UserTable $user * @param string $reason * @param boolean $ajax * @return string */ private function getPointsHTML(&$field, &$user, $reason, $ajax = false) { global $_CB_framework; static $JS_loaded = 0; $userId = (int) $user->get('id'); $fieldName = $field->get('name'); $value = (int) $user->get($fieldName); $readOnly = $this->_isReadOnly($field, $user, $reason); $maxPoints = (int) $field->params->get('integer_maximum', '1000000'); $pointsLayout = $field->params->get('points_layout', ''); $userlistIncrement = (int) $field->params->get('points_list', 0); $userlistAccess = false; if ($reason == 'list') { $fieldName = $fieldName . $userId; if ($userlistIncrement) { $userlistAccess = true; } } $canIncrement = !$readOnly && $this->getIncrementAccess($field, $user) && ($reason == 'list' && $userlistAccess || $reason != 'list'); if ($canIncrement) { $plusCSS = $field->params->get('points_plus_class', ''); $minusCSS = $field->params->get('points_minus_class', ''); $plusIcon = '<span class="' . ($plusCSS ? htmlspecialchars($plusCSS) : 'fa fa-plus-circle fa-lg') . '"></span>'; $minusIcon = '<span class="' . ($minusCSS ? htmlspecialchars($minusCSS) : 'fa fa-minus-circle fa-lg') . '"></span>'; $replace = array('[plus]' => $value < $maxPoints ? '<span class="cbPointsFieldIncrement cbPointsFieldIncrementPlus" data-value="plus" data-field="' . $field->get('name') . '" data-target="' . $userId . '">' . $plusIcon . '</span>' : null, '[minus]' => $value > 0 ? '<span class="cbPointsFieldIncrement cbPointsFieldIncrementMinus" data-value="minus" data-field="' . $field->get('name') . '" data-target="' . $userId . '">' . $minusIcon . '</span>' : null, '[value]' => '<span class="cbPointsFieldValue">' . $value . '</span>'); if ($pointsLayout) { $pointsLayout = CBTxt::Th($pointsLayout, null, $replace); } else { $pointsLayout = CBTxt::Th('POINTS_FIELD_LAYOUT_VALUE_PLUS_MINUS', '[value] [plus] [minus]', $replace); } if ($ajax) { $return = $pointsLayout; } else { $return = '<span id="' . $fieldName . 'Container" class="cbPointsField' . ($userlistAccess ? ' cbClicksInside' : null) . '">' . $pointsLayout . '</span>'; if (!$JS_loaded++) { cbGetRegAntiSpamInputTag(); $cbGetRegAntiSpams = cbGetRegAntiSpams(); $js = "\$( '.cbPointsField' ).on( 'click', '.cbPointsFieldIncrement', function ( e ) {" . "var points = \$( this ).parents( '.cbPointsField' );" . "var increment = \$( this ).data( 'value' );" . "var field = \$( this ).data( 'field' );" . "var target = \$( this ).data( 'target' );" . "\$.ajax({" . "type: 'POST'," . "url: '" . addslashes(cbSef('index.php?option=com_comprofiler&view=fieldclass&function=savevalue&reason=' . urlencode($reason), false, 'raw')) . "'," . "data: {" . "field: field," . "user: target," . "value: increment," . cbSpoofField() . ": '" . addslashes(cbSpoofString(null, 'fieldclass')) . "'," . cbGetRegAntiSpamFieldName() . ": '" . addslashes($cbGetRegAntiSpams[0]) . "'" . "}" . "}).done( function( data, textStatus, jqXHR ) {" . "points.html( data );" . "});" . "});"; $_CB_framework->outputCbJQuery($js); } } } else { $return = parent::getField($field, $user, 'html', $reason, 0); } return $return; }
/** * Accessor: * Returns a field in specified format * * @param FieldTable $field * @param UserTable $user * @param string $output 'html', 'xml', 'json', 'php', 'csvheader', 'csv', 'rss', 'fieldslist', 'htmledit' * @param string $reason 'profile' for user profile view, 'edit' for profile edit, 'register' for registration, 'search' for searches * @param int $list_compare_types IF reason == 'search' : 0 : simple 'is' search, 1 : advanced search with modes, 2 : simple 'any' search * @return mixed */ public function getField( &$field, &$user, $output, $reason, $list_compare_types ) { $return = null; if ( $field->get( 'type' ) == 'comments' ) { $comments = new Comments( 'field', $user, (int) $field->params->get( 'field_comments_direction', 0 ) ); $comments->set( 'type', 'field' ); $comments->set( 'item', (int) $field->get( 'fieldid' ) ); $comments->set( 'parent', (int) $user->get( 'id' ) ); CBActivity::loadStreamDefaults( $comments, $field->params, 'field_comments_' ); $return = $comments->stream( false ); } else { $activity = new Activity( 'field', $user, (int) $field->params->get( 'field_activity_direction', 0 ) ); $activity->set( 'type', 'field' ); $activity->set( 'subtype', 'status' ); $activity->set( 'item', (int) $field->get( 'fieldid' ) ); $activity->set( 'parent', (int) $user->get( 'id' ) ); CBActivity::loadStreamDefaults( $activity, $field->params, 'field_activity_' ); $return = $activity->stream( false ); } if ( ! ( ( $output == 'html' ) && ( $reason == 'profile' ) ) ) { return null; } return $this->formatFieldValueLayout( $this->_formatFieldOutput( $field->get( 'name' ), $return, $output, false ), $reason, $field, $user ); }
/** * Parses profile data for an avatar and uploads it * * @param UserTable $user * @param Hybrid_User_Profile $profile */ private function avatar( &$user, $profile ) { global $_CB_framework, $ueConfig; if ( $profile->photoURL ) { try { $field = new FieldTable(); $field->load( array( 'name' => 'avatar' ) ); $field->set( 'params', new Registry( $field->get( 'params' ) ) ); $conversionType = (int) ( isset( $ueConfig['conversiontype'] ) ? $ueConfig['conversiontype'] : 0 ); $imageSoftware = ( $conversionType == 5 ? 'gmagick' : ( $conversionType == 1 ? 'imagick' : 'gd' ) ); $tmpPath = $_CB_framework->getCfg( 'absolute_path' ) . '/tmp/'; $imagePath = $_CB_framework->getCfg( 'absolute_path' ) . '/images/comprofiler/'; $fileName = uniqid( (string) $profile->identifier . '_' ); $resize = $field->params->get( 'avatarResizeAlways', '' ); if ( $resize == '' ) { if ( isset( $ueConfig['avatarResizeAlways'] ) ) { $resize = $ueConfig['avatarResizeAlways']; } else { $resize = 1; } } $aspectRatio = $field->params->get( 'avatarMaintainRatio', '' ); if ( $aspectRatio == '' ) { if ( isset( $ueConfig['avatarMaintainRatio'] ) ) { $aspectRatio = $ueConfig['avatarMaintainRatio']; } else { $aspectRatio = 1; } } $image = new \CBLib\Image\Image( $imageSoftware, $resize, $aspectRatio ); $avatar = $image->getImagine()->open( $profile->photoURL ); if ( $avatar ) { /** @var GuzzleHttp\ClientInterface $client */ $client = new GuzzleHttp\Client(); $ext = strtolower( preg_replace( '/[^-a-zA-Z0-9_]/', '', pathinfo( $profile->photoURL, PATHINFO_EXTENSION ) ) ); if ( ( ! $ext ) || ( ! in_array( $ext, array( 'jpg', 'jpeg', 'gif', 'png' ) ) ) ) { try { /** @var GuzzleHttp\Message\Response $result */ $result = $client->get( $profile->photoURL ); if ( $result->getStatusCode() == 200 ) { $mime = $result->getHeader( 'Content-Type' ); switch ( $mime ) { case 'image/jpeg': $ext = 'jpg'; break; case 'image/png': $ext = 'png'; break; case 'image/gif': $ext = 'gif'; break; } } } catch ( Exception $e ) {} } if ( ! in_array( $ext, array( 'jpg', 'jpeg', 'gif', 'png' ) ) ) { return; } $tmpAvatar = $tmpPath . $fileName . '.' . $ext; $avatar->save( $tmpAvatar ); $image->setImage( $avatar ); $image->setName( $fileName ); $image->setSource( $tmpAvatar ); $image->setDestination( $imagePath ); $width = $field->params->get( 'avatarWidth', '' ); if ( $width == '' ) { if ( isset( $ueConfig['avatarWidth'] ) ) { $width = $ueConfig['avatarWidth']; } else { $width = 200; } } $height = $field->params->get( 'avatarHeight', '' ); if ( $height == '' ) { if ( isset( $ueConfig['avatarHeight'] ) ) { $height = $ueConfig['avatarHeight']; } else { $height = 500; } } $image->processImage( $width, $height ); $user->set( 'avatar', $image->getCleanFilename() ); $image->setName( 'tn' . $fileName ); $thumbWidth = $field->params->get( 'thumbWidth', '' ); if ( $thumbWidth == '' ) { if ( isset( $ueConfig['thumbWidth'] ) ) { $thumbWidth = $ueConfig['thumbWidth']; } else { $thumbWidth = 60; } } $thumbHeight = $field->params->get( 'thumbHeight', '' ); if ( $thumbHeight == '' ) { if ( isset( $ueConfig['thumbHeight'] ) ) { $thumbHeight = $ueConfig['thumbHeight']; } else { $thumbHeight = 86; } } $image->processImage( $thumbWidth, $thumbHeight ); unlink( $tmpAvatar ); $approval = $field->params->get( 'avatarUploadApproval', '' ); if ( $approval == '' ) { if ( isset( $ueConfig['avatarUploadApproval'] ) ) { $approval = $ueConfig['avatarUploadApproval']; } else { $approval = 1; } } $user->set( 'avatarapproved', ( $approval ? 0 : 1 ) ); } } catch ( Exception $e ) {} } }
/** * Mutator: * Prepares field data for saving to database (safe transfer from $postdata to $user) * Override * * @param FieldTable $field * @param UserTable $user RETURNED populated: touch only variables related to saving this field (also when not validating for showing re-edit) * @param array $postdata Typically $_POST (but not necessarily), filtering required. * @param string $reason 'edit' for save user edit, 'register' for save registration */ public function prepareFieldDataSave( &$field, &$user, &$postdata, $reason ) { $hybrid = new cbconnectHybrid(); $fieldName = $field->get( 'name' ); $provider = $hybrid->getProviderFromField( $fieldName ); $providerId = $hybrid->getIdFromProvider( $provider ); $currentValue = $user->get( $fieldName ); $value = cbGetParam( $postdata, $fieldName ); if ( $currentValue && ( $user->get( 'id' ) == Application::MyUser()->get( 'id' ) ) ) { if ( is_array( $value ) ) { if ( isset( $value[0] ) && ( $value[0] == 1 ) ) { $postdata[$fieldName] = ''; } } $value = cbGetParam( $postdata, $fieldName ); if ( $value === '' ) { try { $adapter = $hybrid->getAdapter( $providerId ); if ( $adapter ) { switch( $provider ) { case 'facebook': /** @noinspection PhpUndefinedMethodInspection */ $adapter->api()->api( '/me/permissions', 'DELETE' ); break; } $adapter->logout(); } } catch ( Exception $e ) {} } } if ( ( ! Application::Cms()->getClientId() ) && $user->get( 'id' ) && $currentValue && ( $value !== '' ) ) { $postdata[$fieldName] = $currentValue; } parent::prepareFieldDataSave( $field, $user, $postdata, $reason ); }
/** * @param FieldTable $field * @param UserTable $user * @param string $output * @param string $formatting * @param string $reason * @param int $list_compare_types * @return mixed|null|string */ public function fieldDisplay( &$field, &$user, $output, $formatting, $reason, $list_compare_types ) { $return = null; if ( ( ! $field->get( '_noCondition', false ) ) && ( ( ! Application::Cms()->getClientId() ) || $this->params->get( 'cond_backend', 0 ) ) ) { $field->set( '_noCondition', true ); if ( $output == 'html' ) { $tabCondition = $this->getTabConditional( (int) $field->get( 'tabid' ), $reason, $user->get( 'id' ) ); $display = true; if ( $tabCondition && in_array( (int) $field->get( 'tabid' ), $tabCondition ) ) { $display = false; } if ( $display ) { $condition = $this->getFieldConditional( null, $reason, $user->get( 'id' ) ); if ( $condition->hide ) { if ( in_array( (int) $field->get( 'fieldid' ), $condition->hide ) ) { $display = false; } } } if ( ! $display ) { $return = ' '; } } elseif ( $output == 'htmledit' ) { $this->getFieldConditional( $field, $reason, $user->id, true ); } $field->set( '_noCondition', false ); } return $return; }
/** * Mutator: * Prepares field data for saving to database (safe transfer from $postdata to $user) * Override * * @param FieldTable $field * @param UserTable $user RETURNED populated: touch only variables related to saving this field (also when not validating for showing re-edit) * @param array $postdata Typically $_POST (but not necessarily), filtering required. * @param string $reason 'edit' for save user edit, 'register' for save registration */ public function prepareFieldDataSave( &$field, &$user, &$postdata, $reason ) { if ( ( ! Application::Cms()->getClientId() ) && ( ! Application::MyUser()->isGlobalModerator() ) && in_array( $reason, array( 'register', 'edit' ) ) ) { $value = cbantispamCaptcha::getInstance( $field->get( 'name' ), $field->params->get( 'cbantispam_captcha_mode', null ) )->getCaptchaInputValue(); $this->validate( $field, $user, null, $value, $postdata, $reason ); } }
/** * @param FieldTable $field * @param UserTable $user * @param array $postdata * @param string $reason */ public function commitFieldDataSave( &$field, &$user, &$postdata, $reason ) { if ( in_array( $reason, array( 'edit', 'register' ) ) ) { $value = implode( '|*|', cbprivacyClass::validatePrivacy( $this->input( $field->get( 'name' ), '0', GetterInterface::RAW ) ) ); if ( $value != '' ) { $privacy = new cbprivacyPrivacyTable(); $query = 'SELECT *' . "\n FROM " . $privacy->getDbo()->NameQuote( $privacy->getTableName() ) . "\n WHERE " . $privacy->getDbo()->NameQuote( 'user_id' ) . " = " . (int) $user->get( 'id' ) . "\n AND " . $privacy->getDbo()->NameQuote( 'type' ) . " = " . $privacy->getDbo()->Quote( 'profile' ) . "\n AND ( " . $privacy->getDbo()->NameQuote( 'subtype' ) . " IS NULL OR " . $privacy->getDbo()->NameQuote( 'subtype' ) . " = " . $privacy->getDbo()->Quote( '' ) . " )"; $privacy->getDbo()->setQuery( $query, 0, 1 ); $privacy->getDbo()->loadObject( $privacy ); if ( ( ! $privacy->get( 'id' ) ) || ( $privacy->get( 'rule' ) != $value ) ) { if ( ! $privacy->get( 'id' ) ) { $privacy->set( 'user_id', (int) $user->get( 'id' ) ); $privacy->set( 'type', 'profile' ); } $privacy->set( 'rule', $value ); $privacy->store(); } } } }