/** * Gets value of field id $fieldId from CB user fields record * * @param int $fieldId * @param boolean $fullAccess IF true do not take in account current user's viewing rights * @return string|null */ public function getFieldValue($fieldId, $fullAccess = false) { $cbUser = CBuser::getInstance((int) $this->id); if ($cbUser) { $fieldContent = $cbUser->getField((int) $fieldId, null, 'php', 'none', 'profile', 0, $fullAccess); if (is_array($fieldContent) && count($fieldContent) > 0) { $value = array_shift($fieldContent); if ($value) { return $value; } if (!$this->fieldIdOfCountry) { $field = new FieldTable(); $field->load(array('name' => 'cb_subs_inv_address_country')); $this->fieldIdOfCountry = $field->fieldid; } if ($fieldId == $this->fieldIdOfCountry) { $value = $this->getInvoiceAddressField('cb_subs_inv_address_country'); $countries = new cbpaidCountries(); $country = $countries->twoLettersToCountry($value); if ($country) { return $country; } } } } return null; }
/** * @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; }
/** * @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 ); } }
/** * 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 ); }
/** * Validator: * Validates $value for $field->required and other rules * 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 string $columnName Column to validate * @param string $value (RETURNED:) Value to validate, Returned Modified if needed ! * @param array $postdata Typically $_POST (but not necessarily), filtering required. * @param string $reason 'edit' for save user edit, 'register' for save registration * @return boolean True if validate, $this->_setErrorMSG if False */ public function validate(&$field, &$user, $columnName, &$value, &$postdata, $reason) { if (Application::MyUser()->getUserId() != $user->get('id')) { // Terms and Conditions should never be required to be accepted by a user other than the profile owner: $field->set('required', 0); } return parent::validate($field, $user, $columnName, $value, $postdata, $reason); }
/** * 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 ) {} } }
/** * BBcode editor * * @uses $this->pbconfig->EnableRating, $this->pbconfig->ShowTitle, $this->pbconfig->ShowName, $this->pbconfig->ShowEmail, $this->pbconfig->UseLocation, $this->pbconfig->LocationField, $this->pbconfig->UseWebAddress, $this->pbconfig->WebField, $this->pbconfig->AllowBBCode, $this->pbconfig->AllowSmiles, $this->pbconfig->Captcha * * @param pbProfileBookEntry $item * @param string $idTag * @param string $htmlAreaLabel * @param string $txtSubmit * @param UserTable $curruser * @param boolean $required * @return string */ function _bbeditor( $item, $idTag, $htmlAreaLabel, $txtSubmit, $curruser, $required ) { global $_CB_framework, $ueConfig; $myId = Application::MyUser()->getUserId(); $newOrMe = ( ( $item->posterid == -1 ) || ( $item->posterid == $myId ) ); $htmltext = '<div class="cbpbEditorContainer" id="div' . $idTag . '">'; //get the CB initiatied form action path this is used for all forms $base_url = $this->_getAbsURLwithParam( array() ); $htmltext .= '<form name="admin' . $idTag . '" id="admin' . $idTag . '" method="post" onsubmit="javascript: return pb_submitForm(this);" action="' . $base_url . "\">\n"; $htmltext .= '<input type="hidden" name="' . $this->_getPagingParamName( 'formaction' . $this->pbconfig->MainMode[0] ) . '" value="' . ( $item->_pbid ? 'edit' : 'new' ) . "\" />\n"; if ( $item->_pbid ) { $htmltext .= '<input type="hidden" name="' . $this->_getPagingParamName( 'id' ) . '" value="' . $item->_pbid . "\" />\n"; } if ( $this->pbconfig->AllowBBCode ) { $editor = $this->getEditor( $idTag ); } else { $editor = null; } $htmltext .= "<table width=\"100%\">\n"; $locationField = null; //Check to see if the Location field should be used if ( $this->pbconfig->UseLocation ) { //Check to see if a registered user is logged in and if the admin has defined a a value for the location field if ( $myId && ( $this->pbconfig->LocationField != 0 ) && $newOrMe ) { $locationField = new FieldTable(); $locationField->load( $this->pbconfig->LocationField ); $naLocationField = $locationField->name; //if they true then display the location value from the users cb profile in read only $locationField = '<td class="titleCell">' . CBTxt::th( "Location" ) . ':<br /><input type="hidden" name="' . $this->_getPagingParamName( 'posterlocation' ) . '" value="' . htmlspecialchars( $curruser->$naLocationField ) . '" />' . htmlspecialchars( $curruser->$naLocationField ) . '</td>'; } else { //else display an entry field to capture the location $locationField = '<td class="titleCell">' . CBTxt::th( "Location" ) . ':<br /><input class="inputbox" type="text" name="' . $this->_getPagingParamName( 'posterlocation' ) . '" value="' . htmlspecialchars( $item->posterlocation ) . '" /></td>'; } } $webField = null; if ( $this->pbconfig->UseWebAddress ) { if ( $myId && ( $this->pbconfig->WebField != 0 ) && $newOrMe ) { $webfield = new FieldTable(); $webfield->load( $this->pbconfig->WebField ); $naWebField = $webfield->name; $webField = '<td class="titleCell">' . CBTxt::th( "Web Address" ) . ':<br /><input type="hidden" name="' . $this->_getPagingParamName( 'posterurl' ) . '" value="' . $curruser->$naWebField . '" />' . $this->_displayWebAddress( $curruser->$naWebField ) . '</td>'; } else { $webField = '<td class="titleCell">' . CBTxt::th( "Web Address" ) . ':<br /><input class="inputbox" type="text" name="' . $this->_getPagingParamName( 'posterurl' ) . '" value="' . htmlspecialchars( $item->posterurl ) . '" /></td>'; } } $htmltext .= "\n<tr>"; if ( ! $myId ) { $htmltext .= '<td class="titleCell">' . CBTxt::th( "Name" ) . ':<br /><input class="inputbox" type="text" name="' . $this->_getPagingParamName( 'postername' ) . '" value="' . htmlspecialchars( $item->postername ) . '" /></td>'; $htmltext .= '<td class="titleCell">' . CBTxt::th( "Email" ) . ':<br /><input class="inputbox" type="text" name="' . $this->_getPagingParamName( 'posteremail' ) . '" value="' . htmlspecialchars( $item->posteremail ) . '" /></td>'; } else { $htmlName = ( $item->postername ? htmlspecialchars( $item->postername ) : getNameFormat( $curruser->name, $curruser->username, $ueConfig['name_format'] ) ); if ( $this->pbconfig->ShowName ) { $htmltext .= '<td class="titleCell">' . CBTxt::th( "Name" ) . ':<br /><input type="hidden" name="' . $this->_getPagingParamName( 'postername' ) . '" value="' . $htmlName . '" />' . $htmlName . '</td>'; } else { $htmltext .= '<td><input type="hidden" name="' . $this->_getPagingParamName( 'postername' ) . '" value="' . $htmlName . '" /></td>'; } if ( $this->pbconfig->ShowEmail ) { $htmltext .= '<td class="titleCell">' . CBTxt::th( "Email" ) . ':<br />'; if ( ! $item->posteremail || $myId == $item->posterid || Application::MyUser()->isAuthorizedToPerformActionOnAsset( 'core.manage', 'com_users' ) ) { $htmltext .= '<input type="hidden" name="' . $this->_getPagingParamName( 'posteremail' ) . '" value="' . ( $item->posteremail ? htmlspecialchars( $item->posteremail ) : htmlspecialchars( $curruser->email ) ) . '" />' . ( $item->posteremail ? htmlspecialchars( $item->posteremail ) : htmlspecialchars( $curruser->email ) ); } else { $htmltext .= CBTxt::th( "Hidden" ); } } else { if ( ! $item->posteremail || $myId == $item->posterid || Application::MyUser()->isAuthorizedToPerformActionOnAsset( 'core.manage', 'com_users' ) ) { $htmltext .= '<td><input type="hidden" name="' . $this->_getPagingParamName( 'posteremail' ) . '" value="' . ( $item->posteremail ? htmlspecialchars( $item->posteremail ) : htmlspecialchars( $curruser->email ) ) . '" /></td>'; } } } $htmltext .= '</tr>'; //Check to see if we are displaying the web address or location field. If we are then add a row for them if ( $webField != null || $locationField != null ) { $htmltext .= "\n<tr>" . $locationField . $webField . '</tr>'; } $htmltext .= '<tr><td colspan="2">'; //Check to see if the admin has enabled rating for profile entries if ( $this->pbconfig->EnableRating && ( $myId != $item->userid ) ) { //Yep its enabled so get the ratings HTML/Code $htmltext .= '<div class="titleCell">' . CBTxt::Th( "User Rating" ) . ':</div>' . '<div class="fieldCell">' . pbcbRatings::getRatingForm( $item->postervote, 'admin' . $idTag, $this->_getPagingParamName( 'postervote' ), ( $this->pbconfig->EnableRating == 3 ) ) . '</div>' ; } // Title line: if ( $this->pbconfig->ShowTitle ) { $htmltext .= '<div class="pbTitleInput">' . '<span class="titleCell">' . CBTxt::Th( "Title" ) . ':</span> ' . '<span class="fieldCell">' . '<input class="form-control pbTitleBox" type="text" name="' . $this->_getPagingParamName( 'postertitle' ) . '" value="' . htmlspecialchars( $item->postertitle ) . '" maxlength="128" />' . '</span>' . '</div>' ; } // Comment editor: $htmltext .= '<div class="pbCommentInput">' . '<span class="titleCell">' . $htmlAreaLabel . ':</span>' . '<span class="fieldCell">' . $editor . '<table class="cbpbEditorTexts"><tr>'; if ( $this->pbconfig->AllowSmiles ) { $htmltext .= "<td width=\"73%\">\n"; } else { $htmltext .= "<td width=\"100%\">\n"; } $htmltext .= '<textarea class="inputbox cbpbEditor" name="' . $this->_getPagingParamName( 'postercomments' ) . '" rows="7" cols ="40" style="width: 95%; overflow:auto;" >' . htmlspecialchars( $item->postercomment ) . "</textarea>\n</td>\n"; if ( $this->pbconfig->AllowSmiles ) { $htmltext .= "<td>\n" . $this->getSmilies( $idTag ) . "</td>\n"; } $htmltext .= "</tr>\n</table>\n" . '</span>' . '</div>' . '</td></tr>'; // Captcha integration: if ( ( $this->pbconfig->Captcha == 2 ) || ( ( $this->pbconfig->Captcha == 1 ) && ( $curruser === null ) ) ) { global $_PLUGINS; $_PLUGINS->loadPluginGroup( 'user' ); $pluginsResults = $_PLUGINS->trigger( 'onGetCaptchaHtmlElements', array( true ) ); // onCheckCaptchaHtmlElements if ( implode( $pluginsResults ) != '' ) { $htmltext .= '<tr><td colspan="2">' . implode( '</td></tr><tr><td colspan="2">', $pluginsResults ) . '</td></tr>'; } } $htmltext .= '<tr><td colspan="2"><span class="fieldCell"><input class="button" name="submitentry" type="submit" value="' . $txtSubmit . "\" /></span></td></tr>\n"; $htmltext .= "</table>\n"; $htmltext .= "</form>\n"; $htmltext .= "</div>\n"; //Add the localized Javascript parameters so that error messages are properly translated $validateArray = array(); if ( $required ) { $validateArray[] = array( 'field' => 'postername', 'confirm' => null, 'error' => CBTxt::T( "Name is Required!" ) ); $validateArray[] = array( 'field' => 'posteremail', 'confirm' => null, 'error' => CBTxt::T( "Email Address is Required!" ) ); } if ( $myId != $item->userid ) { if ( $this->pbconfig->EnableRating == 3 ) { $validateArray[] = array( 'field' => 'postervote', 'confirm' => null, 'error' => CBTxt::T( "User Rating is Required!" ) ); } elseif ( $this->pbconfig->EnableRating == 2 ) { $validateArray[] = array( 'field' => 'postervote', 'confirm' => CBTxt::T( "You have not selected a User Rating. Do you really want to provide an Entry without User Rating ?" ), 'error' => null ); } } if ( $this->pbconfig->ShowTitle ) { $validateArray[] = array( 'field' => 'postertitle', 'confirm' => null, 'error' => CBTxt::T( "Title is Required!" ) ); } $validateArray[] = array( 'field' => 'postercomments', 'confirm' => null, 'error' => CBTxt::T( "Comment is Required!" ) ); $res = array(); foreach ( $validateArray as $validateField ) { $res[] = "Array('" . addslashes( $this->_getPagingParamName( $validateField['field'] ) ) . "'," . "'" . addslashes( $validateField['confirm'] ) . "'," . "'" . addslashes( $validateField['error'] ) . "')"; } $_CB_framework->document->addHeadScriptDeclaration( 'var _admin' . $idTag . '_validations = Array( ' . implode( ',', $res ) . ");\n" . 'var _admin' . $idTag . "_bbcodestack = Array();\n" ); return $htmltext; }
/** * Generic check for whether dependancies exist for this object in the db schema * * @param int $oid key index (only int supported here) * @return boolean */ function canDelete($oid = null) { if ($oid === null) { $k = $this->_tbl_key; $oid = $this->{$k}; } if ($this->sys) { $this->_error = CBTxt::T('System tabs cannot be deleted!'); return false; } if ($this->pluginid) { $plugin = new PluginTable($this->_db); if ($plugin->load($this->pluginid)) { $this->_error = CBTxt::T('Plugin tabs cannot be deleted!'); return false; } } // Check if tab still has fields: $fieldObject = new FieldTable($this->_db); if ($fieldObject->countFieldsOfTab($oid)) { $this->_error = CBTxt::T('Tabs with fields cannot be deleted!'); return false; } return parent::canDelete($oid); }
/** * 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 ); }
/** * Deletes tabs and private fields of plugin id * * @param int $id id of plugin */ function deleteTabAndFieldsOfPlugin($id) { global $_CB_database; //Find all tabs related to this plugin $_CB_database->setQuery("SELECT `tabid`, `fields` FROM #__comprofiler_tabs WHERE pluginid=" . (int) $id); $tabs = $_CB_database->loadObjectList(); if (count($tabs) > 0) { $rowTab = new TabTable(); foreach ($tabs as $tab) { //Find all fields related to the tab $_CB_database->setQuery("SELECT `fieldid`, `name` FROM #__comprofiler_fields WHERE `tabid`=" . (int) $tab->tabid . " AND `pluginid`=" . (int) $id); $fields = $_CB_database->loadObjectList(); $rowField = new FieldTable(); //Delete fields and fieldValues, but not data content itself in the comprofilier table so they stay on reinstall if (count($fields) > 0) { //delete each field related to a tab and all field value related to a field, but not the content foreach ($fields as $field) { //Now delete the field itself without deleting the user data, preserving it for reinstall //$rowField->deleteColumn('#__comprofiler',$field->name); // this would delete the user data $rowField->delete($field->fieldid); } } if ($tab->fields) { $_CB_database->setQuery("SELECT COUNT(*) FROM #__comprofiler_fields WHERE tabid=" . (int) $tab->tabid); $fieldsCount = $_CB_database->loadResult(); if ($fieldsCount > 0) { $_CB_database->setQuery("UPDATE #__comprofiler_tabs SET `pluginclass`=null, `pluginid`=null WHERE `tabid`=" . (int) $tab->tabid); $_CB_database->query(); } else { //delete each tab $rowTab->delete($tab->tabid); } } else { //delete each tab $rowTab->delete($tab->tabid); } } } //Find all fields related to this plugin which are in other tabs, are calculated and delete them as they are of no use anymore: $_CB_database->setQuery("SELECT `fieldid`, `name` FROM #__comprofiler_fields WHERE `calculated`=1 AND `sys`=0 AND `pluginid`=" . (int) $id); $fields = $_CB_database->loadObjectList(); $rowField = new FieldTable(); if (count($fields) > 0) { foreach ($fields as $field) { //Now delete the field itself: $rowField->delete($field->fieldid); } } //Find all fields related to this plugin and set to NULL the now uninstalled plugin. $_CB_database->setQuery("SELECT COUNT(*) FROM #__comprofiler_fields WHERE pluginid=" . (int) $id); $fieldsNumber = $_CB_database->loadResult(); if ($fieldsNumber > 0) { $_CB_database->setQuery("UPDATE #__comprofiler_fields SET pluginid = NULL WHERE pluginid=" . (int) $id); $_CB_database->query(); } }
/** * Sets a CB field id $fieldId to $value * * @param int $fieldId * @param mixed $value * @param boolean $fullAccess IF true do not take in account current user's viewing rights * @return boolean TRUE: Field value could be set, FALSE: User or Field not found */ public function setFieldValue( $fieldId, $value, $fullAccess = false ) { $cbUser = CBuser::getInstance( (int) $this->id ); if ( $cbUser ) { $fieldContent = $cbUser->getField( (int) $fieldId, null, 'php', 'none', 'profile', 0, $fullAccess ); $user = $cbUser->getUserData(); if ( $user ) { if ( ! ( is_array( $fieldContent ) && ( count( $fieldContent ) > 0 ) ) ) { //TODO: REMOVE WHEN CB 1.5 is required: // Now this is a quick hack to get a value from a field that is not visible on profile but still in database: $field = new FieldTable( $this->_db ); if ( $field->load( (int) $fieldId ) ) { $fieldCol = $field->tablecolumns; if ( isset( $user->$fieldCol ) ) { $fieldContent = array( $fieldCol => $user->$fieldCol ); } } } if ( is_array( $fieldContent ) && ( count( $fieldContent ) > 0 ) ) { foreach ( $fieldContent as $fName => $fValue ) { $user->$fName = $value; return true; } } } } return false; }
function cbInstaller_install_plugins(&$return) { global $_CB_framework, $_CB_adminpath, $ueConfig; cbimport('cb.adminfilesystem'); cbimport('cb.installer'); $cbDatabase = \CBLib\Application\Application::Database(); // List of core plugins that are no longer core, but we just want to disable core status and not remove as they don't conflict: $deprecated = array('bootstrap', 'winclassic', 'webfx', 'osx', 'luna', 'dark', 'yanc', 'cb.mamblogtab', 'cb.simpleboardtab', 'cb.authortab'); foreach ($deprecated as $pluginElement) { $plugin = new PluginTable(); if ($plugin->load(array('element' => $pluginElement))) { $query = "UPDATE " . $cbDatabase->NameQuote('#__comprofiler_plugin') . "\n SET " . $cbDatabase->NameQuote('iscore') . " = 0" . "\n WHERE " . $cbDatabase->NameQuote('id') . " = " . (int) $plugin->id; $cbDatabase->setQuery($query); if (!$cbDatabase->query()) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Plugin [element] failed to deprecate. Please run Tools > Check Community Builder Database to reattempt.', array('[element]' => $pluginElement)) . '</div>'; } $query = "UPDATE " . $cbDatabase->NameQuote('#__comprofiler_tabs') . "\n SET " . $cbDatabase->NameQuote('sys') . " = 0" . "\n WHERE " . $cbDatabase->NameQuote('pluginid') . " = " . (int) $plugin->id; $cbDatabase->setQuery($query); if (!$cbDatabase->query()) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Plugin [element] tabs failed to deprecate. Please run Tools > Check Community Builder Database to reattempt.', array('[element]' => $pluginElement)) . '</div>'; } $query = "UPDATE " . $cbDatabase->NameQuote('#__comprofiler_fields') . "\n SET " . $cbDatabase->NameQuote('sys') . " = 0" . "\n WHERE " . $cbDatabase->NameQuote('pluginid') . " = " . (int) $plugin->id; $cbDatabase->setQuery($query); if (!$cbDatabase->query()) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Plugin [element] fields failed to deprecate. Please run Tools > Check Community Builder Database to reattempt.', array('[element]' => $pluginElement)) . '</div>'; } } } // List of plugins that conflict with the core that need to be removed (normally due to being merged into core): $conflicted = array('bootstrap', 'winclassic', 'webfx', 'osx', 'luna', 'dark', 'yanc', 'cb.mamblogtab', 'cb.authortab', 'cbvideofield', 'cb.filefield'); foreach ($conflicted as $pluginElement) { $plugin = new PluginTable(); if ($plugin->load(array('element' => $pluginElement))) { if (!cbInstaller_uninstall_plugin($plugin, $return)) { return false; } } } // Ensure Default template, CB Core, and language plugins are published as they are not allowed to be unpublished: $query = "UPDATE " . $cbDatabase->NameQuote('#__comprofiler_plugin') . "\n SET " . $cbDatabase->NameQuote('published') . " = 1" . "\n WHERE ( " . $cbDatabase->NameQuote('id') . " IN " . $cbDatabase->safeArrayOfIntegers(array(1, 7)) . ' OR ' . $cbDatabase->NameQuote('type') . ' = ' . $cbDatabase->quote('language') . ' )'; $cbDatabase->setQuery($query); $cbDatabase->query(); $pluginsFile = $_CB_adminpath . 'pluginsfiles.tgz'; // We need to ensure the core plugins archive actually exists before doing anything with it: if (!file_exists($pluginsFile)) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Core plugins archive [path] missing.', array('[path]' => $pluginsFile)) . '</div>'; return false; } // We need zlib to unzip packages so lets check that it exists: if (!extension_loaded('zlib')) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::T('Core plugins can not be installed as zlib is not installed.') . '</div>'; return false; } $installer = new cbInstallerPlugin(); // Uncompress the core plugins so we can install them: if (!$installer->upload($pluginsFile, true, false)) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Core plugins can not be installed as uncompressing [path] failed.', array('[path]' => $pluginsFile)) . '</div>'; return false; } $adminFS = cbAdminFileSystem::getInstance(); $baseDir = $_CB_framework->getCfg('absolute_path') . '/components/com_comprofiler'; // Create the base plugin directory: if (!$adminFS->is_dir($baseDir . '/plugin')) { if (!$adminFS->mkdir($baseDir . '/plugin')) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Failed to create directory [path].', array('[path]' => $baseDir . '/plugin')) . '</div>'; return false; } if (!$adminFS->copy($baseDir . '/index.html', $baseDir . '/plugin/index.html')) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Failed to create index [path].', array('[path]' => $baseDir . '/plugin/index.html')) . '</div>'; return false; } } // Create the language template directory: if (!$adminFS->is_dir($baseDir . '/plugin/language')) { if (!$adminFS->mkdir($baseDir . '/plugin/language')) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Failed to create directory [path].', array('[path]' => $baseDir . '/plugin/language')) . '</div>'; return false; } if (!$adminFS->copy($baseDir . '/index.html', $baseDir . '/plugin/language/index.html')) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Failed to create index [path].', array('[path]' => $baseDir . '/plugin/language/index.html')) . '</div>'; return false; } } // Create the template plugin directory: if (!$adminFS->is_dir($baseDir . '/plugin/templates')) { if (!$adminFS->mkdir($baseDir . '/plugin/templates')) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Failed to create directory [path].', array('[path]' => $baseDir . '/plugin/templates')) . '</div>'; return false; } if (!$adminFS->copy($baseDir . '/index.html', $baseDir . '/plugin/templates/index.html')) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Failed to create index [path].', array('[path]' => $baseDir . '/plugin/templates/index.html')) . '</div>'; return false; } } // Create the user plugin directory: if (!$adminFS->is_dir($baseDir . '/plugin/user')) { if (!$adminFS->mkdir($baseDir . '/plugin/user')) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Failed to create directory [path].', array('[path]' => $baseDir . '/plugin/user')) . '</div>'; return false; } if (!$adminFS->copy($baseDir . '/index.html', $baseDir . '/plugin/user/index.html')) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Failed to create index [path].', array('[path]' => $baseDir . '/plugin/user/index.html')) . '</div>'; return false; } } // Install core plugins 1 by 1 silently: $installFrom = $installer->installDir(); $filesList = cbReadDirectory($installFrom, '.', true); foreach ($filesList as $file) { if (preg_match('/^.+\\.xml$/i', $file)) { $plgPath = $installFrom . (substr($installFrom, -1, 1) == '/' ? '' : '/') . $file; $plgXml = new SimpleXMLElement(trim(file_get_contents($plgPath))); if ($plgXml->getName() == 'cbinstall') { $plgDir = dirname($plgPath) . '/'; ob_start(); $plgInstaller = new cbInstallerPlugin(); $installed = $plgInstaller->install($plgDir); ob_end_clean(); if (!$installed) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Installing core plugin [plugin] failed with error [error].', array('[plugin]' => $plgInstaller->i_elementname ? $plgInstaller->i_elementname : $file, '[error]' => $plgInstaller->getError())) . '</div>'; return false; } } } } // Delete the expanded core plugins archive: $result = $adminFS->deldir(_cbPathName($installFrom . '/')); if ($result === false) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::T('Deleting expanded core plugins archive failed.') . '</div>'; } // Delete the core plugins archive: $result = $adminFS->unlink(_cbPathName($pluginsFile, false)); if ($result === false) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Deleting core plugins archive [path] failed.', array('[path]' => $pluginsFile)) . '</div>'; } // Sets the as ready so config can actually load this time: \CB\Application\CBConfig::setCbConfigReadyToLoad(true); // Load the config now that the tables exist encase they didn't during install: \CB\Application\CBConfig::loadLegacyCBueConfig(); // Migrate old file based configuration to database based configuration: $newConfig = null; if ($adminFS->file_exists($_CB_adminpath . 'ue_config.php')) { /** @noinspection PhpIncludeInspection */ include_once $_CB_adminpath . 'ue_config.php'; // Reset the template back to default if upgrading from a 1.x install: $ueConfig['templatedir'] = 'default'; $newConfig = json_encode($ueConfig); } // Convert CB 1.x nesttabs into new nested tab display mode if needed: if (isset($ueConfig['nesttabs'])) { // Update all the tabs that would have normally auto-nested and make them nested displays $query = 'UPDATE ' . $cbDatabase->NameQuote('#__comprofiler_tabs') . "\n SET " . $cbDatabase->NameQuote('displaytype') . " = " . $cbDatabase->Quote('nested') . "\n WHERE " . $cbDatabase->NameQuote('displaytype') . " = " . $cbDatabase->Quote('tab') . "\n AND " . $cbDatabase->NameQuote('fields') . " = 1" . "\n AND ( ( " . $cbDatabase->NameQuote('pluginclass') . " IS NULL )" . ' OR ( ' . $cbDatabase->NameQuote('sys') . ' = 2 ) )'; $cbDatabase->setQuery($query); $cbDatabase->query(); unset($ueConfig['nesttabs']); $newConfig = json_encode($ueConfig); } // Migrate global avatar params to field params: if (isset($ueConfig['allowAvatar']) || isset($ueConfig['defaultAvatar']) || isset($ueConfig['defaultPendingAvatar']) || isset($ueConfig['allowAvatarGallery'])) { $field = new FieldTable(); if ($field->load(array('name' => 'avatar'))) { $fieldParams = new Registry($field->params); if (isset($ueConfig['allowAvatar'])) { $fieldParams->set('image_allow_uploads', (int) $ueConfig['allowAvatar']); unset($ueConfig['allowAvatar']); } if (isset($ueConfig['defaultAvatar'])) { $fieldParams->set('defaultAvatar', $ueConfig['defaultAvatar']); unset($ueConfig['defaultAvatar']); } if (isset($ueConfig['defaultPendingAvatar'])) { $fieldParams->set('defaultPendingAvatar', $ueConfig['defaultPendingAvatar']); unset($ueConfig['defaultPendingAvatar']); } if (isset($ueConfig['allowAvatarGallery'])) { $fieldParams->set('image_allow_gallery', (int) $ueConfig['allowAvatarGallery']); unset($ueConfig['allowAvatarGallery']); } $field->set('params', $fieldParams->asJson()); if (!$field->store()) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Field [name] failed to migrate. Error: [error]', array('[name]' => $field->name, '[error]' => $field->getError())) . '</div>'; } } $newConfig = json_encode($ueConfig); } // Migrate global email ajax checker to field specific param: if (isset($ueConfig['reg_email_checker'])) { $field = new FieldTable(); if ($field->load(array('name' => 'email'))) { $fieldParams = new Registry($field->params); $fieldParams->set('field_check_email', (string) $ueConfig['reg_email_checker']); $field->set('params', $fieldParams->asJson()); if (!$field->store()) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Field [name] failed to migrate. Error: [error]', array('[name]' => $field->name, '[error]' => $field->getError())) . '</div>'; } } unset($ueConfig['reg_email_checker']); $newConfig = json_encode($ueConfig); } // Migrate global image params to field params: if (isset($ueConfig['allowAvatarUpload'])) { $query = 'SELECT *' . "\n FROM " . $cbDatabase->NameQuote('#__comprofiler_fields') . "\n WHERE " . $cbDatabase->NameQuote('name') . " != " . $cbDatabase->Quote('avatar') . "\n AND " . $cbDatabase->NameQuote('type') . " = " . $cbDatabase->Quote('image'); $cbDatabase->setQuery($query); $fields = $cbDatabase->loadObjectList(null, '\\CB\\Database\\Table\\FieldTable', array($cbDatabase)); /** @var $fields FieldTable[] */ foreach ($fields as $field) { $fieldParams = new Registry($field->params); $fieldParams->set('image_allow_uploads', (int) $ueConfig['allowAvatarUpload']); $field->set('params', $fieldParams->asJson()); if (!$field->store()) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Field [name] failed to migrate. Error: [error]', array('[name]' => $field->name, '[error]' => $field->getError())) . '</div>'; } } unset($ueConfig['allowAvatarUpload']); $newConfig = json_encode($ueConfig); } // Convert CB 1.x allow_profileviewbyGID into new profile_viewaccesslevel if needed: if (isset($ueConfig['allow_profileviewbyGID']) && !isset($ueConfig['profile_viewaccesslevel'])) { $ueConfig['profile_viewaccesslevel'] = \CBLib\Application\Application::CmsPermissions()->convertOldGroupToViewAccessLevel($ueConfig['allow_profileviewbyGID'], 'CB Profiles access'); unset($ueConfig['allow_profileviewbyGID']); $newConfig = json_encode($ueConfig); } // Convert CB 1.x allow_profileviewbyGID into new profile_viewaccesslevel if needed: if (isset($ueConfig['imageApproverGid']) && !isset($ueConfig['moderator_viewaccesslevel'])) { $ueConfig['moderator_viewaccesslevel'] = \CBLib\Application\Application::CmsPermissions()->convertOldGroupToViewAccessLevel($ueConfig['imageApproverGid'], 'CB Moderators access'); unset($ueConfig['imageApproverGid']); $newConfig = json_encode($ueConfig); } // If old configuration for terms and conditions exists we need to pass it to the terms and conditions field: if (isset($ueConfig['reg_enable_toc']) && isset($ueConfig['reg_toc_url'])) { if ($ueConfig['reg_enable_toc'] == 1 && $ueConfig['reg_toc_url'] != '') { $field = new FieldTable(); if ($field->load(array('name' => 'acceptedterms'))) { $fieldParams = new Registry($field->params); if ($fieldParams->get('terms_url') == '') { $fieldParams->set('terms_url', $ueConfig['reg_toc_url']); $field->set('required', 1); $field->set('registration', 1); $field->set('edit', 1); $field->set('params', $fieldParams->asJson()); if (!$field->store()) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Field [name] failed to migrate. Error: [error]', array('[name]' => $field->name, '[error]' => $field->getError())) . '</div>'; } } } } unset($ueConfig['reg_enable_toc']); unset($ueConfig['reg_toc_url']); $newConfig = json_encode($ueConfig); } // If old configuration for userlists exists we need to pass it to the userlist it self: if (isset($ueConfig['num_per_page']) && isset($ueConfig['allow_profilelink'])) { if ($ueConfig['num_per_page'] != '' || $ueConfig['allow_profilelink'] != 1) { $query = 'SELECT *' . "\n FROM " . $cbDatabase->NameQuote('#__comprofiler_lists'); $cbDatabase->setQuery($query); $lists = $cbDatabase->loadObjectList(null, '\\CB\\Database\\Table\\ListTable', array($cbDatabase)); /** @var $lists ListTable[] */ foreach ($lists as $list) { $listParams = new Registry($list->params); $changed = false; if ($ueConfig['num_per_page'] != '' && $listParams->get('list_limit') == '') { $listParams->set('list_limit', $ueConfig['num_per_page']); $changed = true; } if ($ueConfig['allow_profilelink'] != 1 && $listParams->get('allow_profilelink') == '') { $listParams->set('allow_profilelink', $ueConfig['allow_profilelink']); $changed = true; } if ($changed) { $list->set('params', $listParams->asJson()); if (!$list->store()) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Userlist [title] failed to migrate. Error: [error]', array('[name]' => $list->title, '[error]' => $list->getError())) . '</div>'; } } } } unset($ueConfig['num_per_page']); unset($ueConfig['allow_profilelink']); $newConfig = json_encode($ueConfig); } // Establish default for any missing config params: $configXml = new SimpleXMLElement(trim(file_get_contents($_CB_adminpath . 'xmlcb/views/view.com_comprofiler.editconfig.xml'))); if ($configXml) { $configXmlParams = $configXml->xpath('//param'); if ($configXmlParams) { $configXmlSet = false; foreach ($configXmlParams as $configXmlParam) { $k = (string) $configXmlParam->attributes('name'); if (!isset($ueConfig[$k])) { $v = (string) $configXmlParam->attributes('default'); if ($k) { $ueConfig[$k] = $v; $configXmlSet = true; } } } if ($configXmlSet) { $newConfig = json_encode($ueConfig); } } } // Update cb.core with the new cb config: if ($newConfig) { $query = "UPDATE " . $cbDatabase->NameQuote('#__comprofiler_plugin') . "\n SET " . $cbDatabase->NameQuote('params') . " = " . $cbDatabase->Quote($newConfig) . "\n WHERE " . $cbDatabase->NameQuote('id') . " = 1"; $cbDatabase->setQuery($query); if (!$cbDatabase->query()) { $_CB_framework->enqueueMessage(CBTxt::P('Failed to update configuration params in database. Error: [error]', array('[error]' => $cbDatabase->getErrorMsg())), 'error'); return false; } } // Remove the old config file if it exists as we migrated above already: if ($adminFS->file_exists($_CB_adminpath . 'ue_config.php')) { $adminFS->unlink($_CB_adminpath . 'ue_config.php'); } // Migrate old userlist columns to new usage: $tableFields = $cbDatabase->getTableFields('#__comprofiler_lists'); if (isset($tableFields['#__comprofiler_lists'])) { $userListFields = array_keys($tableFields['#__comprofiler_lists']); $userListOldFields = array('useraccessgroupid', 'sortfields', 'filterfields', 'col1title', 'col1enabled', 'col1fields', 'col1captions', 'col2title', 'col2enabled', 'col2fields', 'col2captions', 'col3title', 'col3enabled', 'col3fields', 'col3captions', 'col4title', 'col4enabled', 'col4fields', 'col4captions'); // At least 1 legacy column still exists so lets begin migration of userlists: if (array_intersect($userListOldFields, $userListFields)) { $query = 'SELECT *' . "\n FROM " . $cbDatabase->NameQuote('#__comprofiler_lists'); $cbDatabase->setQuery($query); $lists = $cbDatabase->loadObjectList(null, '\\CB\\Database\\Table\\ListTable', array($cbDatabase)); /** @var $lists ListTable[] */ foreach ($lists as $list) { $listParams = new Registry($list->params); $listSorting = array(); $listSortFields = $list->get('sortfields') ? explode(', ', str_replace('`', '', $list->get('sortfields'))) : array(); $paramsChanged = false; foreach ($listSortFields as $listSortField) { $sortParts = explode(' ', $listSortField); $sortField = isset($sortParts[0]) ? trim($sortParts[0]) : null; if ($sortField) { $sortDirection = isset($sortParts[1]) ? trim($sortParts[1]) : 'ASC'; $listSorting[] = array('column' => $sortField, 'direction' => $sortDirection); } } if ($listSorting) { $paramsChanged = true; $listParams->set('sort_mode', '0'); $listParams->set('basic_sort', $listSorting); } $listFilterFields = $list->get('filterfields'); if ($listFilterFields) { $filterType = substr($listFilterFields, 0, 1); $listFilterFields = rawurldecode(substr($listFilterFields, 2, -1)); if ($filterType == 'a') { $paramsChanged = true; $listParams->set('filter_mode', '1'); $listParams->set('filter_advanced', $listFilterFields); } else { $listFilters = array(); $basicFilters = explode(' AND ', $listFilterFields); foreach ($basicFilters as $basicFilter) { if (preg_match('/`(.+)`\\s*(.+)\\s*\'(.*)\'|`(.+)`\\s*(.+)/i', $basicFilter, $matches)) { $filterField = isset($filterParts[1]) ? $filterParts[1] : (isset($filterParts[4]) ? $filterParts[4] : null); $filterOperator = isset($filterParts[2]) ? $filterParts[2] : (isset($filterParts[5]) ? $filterParts[5] : null); $filterVal = isset($filterParts[3]) ? $filterParts[3] : ''; switch ($filterOperator) { case '!=': $filterOperator = '<>||ISNULL'; break; case 'IS NULL': case "= ''": $filterOperator = '='; $filterVal = ''; break; case 'IS NOT NULL': case "!= ''": $filterOperator = '!='; $filterVal = ''; break; } if ($filterField && $filterOperator) { $listFilters[] = array('column' => $filterField, 'operator' => $filterOperator, 'value' => $filterVal); } } } if ($listFilters) { $paramsChanged = true; $listParams->set('filter_mode', '0'); $listParams->set('filter_basic', $listFilters); } } } $listColumns = array(); for ($i = 1, $n = 4; $i <= $n; $i++) { if ($list->get('col' . $i . 'enabled')) { $columnTitle = $list->get('col' . $i . 'title', ''); $columnCaptions = (int) $list->get('col' . $i . 'captions', 0); $columnFields = $list->get('col' . $i . 'fields') ? explode('|*|', $list->get('col' . $i . 'fields')) : array(); $listFields = array(); foreach ($columnFields as $columnField) { $listFields[] = array('field' => (string) $columnField, 'display' => $columnCaptions ? '1' : '4'); } if ($listFields) { $listColumns[] = array('title' => $columnTitle, 'size' => '3', 'cssclass' => '', 'fields' => $listFields); } } } if ($listColumns) { $paramsChanged = true; $listParams->set('columns', $listColumns); } if ($paramsChanged || $list->get('usergroupids')) { $list->set('usergroupids', implode('|*|', explode(', ', $list->get('usergroupids')))); $list->set('params', $listParams->asJson()); if (!$list->store()) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Userlist [title] failed to migrate. Error: [error]', array('[name]' => $list->title, '[error]' => $list->getError())) . '</div>'; } } } $userListDrop = array(); foreach ($userListOldFields as $userListOldField) { if (in_array($userListOldField, $userListFields)) { $userListDrop[] = $cbDatabase->NameQuote($userListOldField); } } if ($userListDrop) { $query = 'ALTER TABLE ' . $cbDatabase->NameQuote('#__comprofiler_lists') . "\n DROP " . implode(', DROP ', $userListDrop); $cbDatabase->setQuery($query); $cbDatabase->query(); } } } // Migrates password strength parameters: $plugin = new PluginTable(); if ($plugin->load(array('element' => 'cbpasswordstrength'))) { $query = "SELECT *" . "\n FROM " . $cbDatabase->NameQuote('#__comprofiler_fields') . "\n WHERE " . $cbDatabase->NameQuote('type') . " = " . $cbDatabase->Quote('password'); $cbDatabase->setQuery($query); $fields = $cbDatabase->loadObjectList(null, '\\CB\\Database\\Table\\FieldTable', array($cbDatabase)); /** @var $fields FieldTable[] */ foreach ($fields as $field) { $fieldParams = new Registry($field->params); $fieldParams->set('passTestSrength', (string) $fieldParams->get('pswstr_display', 1)); $field->set('params', $fieldParams->asJson()); if (!$field->store()) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Field [name] failed to migrate. Error: [error]', array('[name]' => $field->name, '[error]' => $field->getError())) . '</div>'; } } if (!cbInstaller_uninstall_plugin($plugin, $return)) { return false; } } // Migrates ajax points field parameters: $plugin = new PluginTable(); if ($plugin->load(array('element' => 'cbajaxpointsfield'))) { $query = "SELECT *" . "\n FROM " . $cbDatabase->NameQuote('#__comprofiler_fields') . "\n WHERE " . $cbDatabase->NameQuote('type') . " = " . $cbDatabase->Quote('ajaxpoints'); $cbDatabase->setQuery($query); $fields = $cbDatabase->loadObjectList(null, '\\CB\\Database\\Table\\FieldTable', array($cbDatabase)); /** @var $fields FieldTable[] */ foreach ($fields as $field) { $fieldParams = new Registry($field->params); switch ((int) $fieldParams->get('ajax_layout', 1)) { case 1: $fieldParams->set('points_layout', '[minus] [value] [plus]'); break; case 2: $fieldParams->set('points_layout', '[plus] [value] [minus]'); break; case 3: $fieldParams->set('points_layout', '[value] [minus][plus]'); break; case 4: $fieldParams->set('points_layout', '[value] [plus][minus]'); break; case 5: $fieldParams->set('points_layout', '[minus][plus] [value]'); break; case 6: $fieldParams->set('points_layout', '[plus][minus] [value]'); break; } $fieldParams->set('points_inc_plus', (string) $fieldParams->get('ajax_increment_up', 1)); $fieldParams->set('points_inc_minus', (string) $fieldParams->get('ajax_increment_down', 1)); $fieldParams->set('points_access', '8'); $fieldParams->set('points_access_custom', (string) $fieldParams->get('ajax_access', 0)); $field->set('type', 'points'); $field->set('pluginid', 1); $field->set('params', $fieldParams->asJson()); if (!$field->store()) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Field [name] failed to migrate. Error: [error]', array('[name]' => $field->name, '[error]' => $field->getError())) . '</div>'; } } if (!cbInstaller_uninstall_plugin($plugin, $return)) { return false; } } // Migrates rating field parameters: $plugin = new PluginTable(); if ($plugin->load(array('element' => 'ratingfield'))) { $query = "SELECT *" . "\n FROM " . $cbDatabase->NameQuote('#__comprofiler_fields') . "\n WHERE " . $cbDatabase->NameQuote('type') . " IN " . $cbDatabase->safeArrayOfStrings(array('myrating', 'yourrating')); $cbDatabase->setQuery($query); $fields = $cbDatabase->loadObjectList(null, '\\CB\\Database\\Table\\FieldTable', array($cbDatabase)); /** @var $fields FieldTable[] */ foreach ($fields as $field) { $fieldParams = new Registry($field->params); if ($field->type == 'myrating') { $fieldParams->set('rating_access', '2'); } else { if ($fieldParams->get('AllowAnnonymous', 1)) { $fieldParams->set('rating_access', '3'); } else { $fieldParams->set('rating_access', '4'); $fieldParams->set('rating_access_exclude', '1'); } } $fieldParams->set('rating_number', (string) $fieldParams->get('NumStars', 5)); switch ((int) $fieldParams->get('RatingFraction', 1)) { case 1: $fieldParams->set('rating_step', '1'); break; case 2: $fieldParams->set('rating_step', '0.5'); break; case 3: $fieldParams->set('rating_step', '0.33'); break; case 4: $fieldParams->set('rating_step', '0.25'); break; } $field->set('type', 'rating'); $field->set('pluginid', 1); $field->set('params', $fieldParams->asJson()); if (!$field->store()) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Field [name] failed to migrate. Error: [error]', array('[name]' => $field->name, '[error]' => $field->getError())) . '</div>'; } } if (!cbInstaller_uninstall_plugin($plugin, $return)) { return false; } } // Migrates verify email field parameters: $plugin = new PluginTable(); if ($plugin->load(array('element' => 'cbverifyemail'))) { $query = "SELECT *" . "\n FROM " . $cbDatabase->NameQuote('#__comprofiler_fields') . "\n WHERE " . $cbDatabase->NameQuote('type') . " IN " . $cbDatabase->safeArrayOfStrings(array('emailaddress', 'primaryemailaddress')); $cbDatabase->setQuery($query); $fields = $cbDatabase->loadObjectList(null, '\\CB\\Database\\Table\\FieldTable', array($cbDatabase)); /** @var $fields FieldTable[] */ foreach ($fields as $field) { $fieldParams = new Registry($field->params); $fieldParams->set('fieldVerifyInput', $fieldParams->get('verifyemail_display_reg', 1) || $fieldParams->get('verifyemail_display_edit', 0) ? '1' : '0'); $fieldParams->set('verifyEmailTitle', $fieldParams->get('verifyemail_title', '_UE_VERIFY_SOMETHING')); $field->set('params', $fieldParams->asJson()); if (!$field->store()) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Field [name] failed to migrate. Error: [error]', array('[name]' => $field->name, '[error]' => $field->getError())) . '</div>'; } } if (!cbInstaller_uninstall_plugin($plugin, $return)) { return false; } } // Migrates forum integration parameters: $plugin = new PluginTable(); if ($plugin->load(array('element' => 'cb.simpleboardtab'))) { $pluginParams = new Registry($plugin->params); $cbForums = new PluginTable(); if ($cbForums->load(array('element' => 'cbforums'))) { $cbForumsParams = new Registry($cbForums->params); if ((int) $pluginParams->get('forumType', 0) == 4) { $cbForumsParams->set('forum_model', '6'); } else { $cbForumsParams->set('forum_model', '1'); } switch ((int) $pluginParams->get('sidebarMode', 0)) { case 1: $cbForumsParams->set('k20_personaltext', $pluginParams->get('sidebarBeginner1')); $cbForumsParams->set('k20_gender', $pluginParams->get('sidebarBeginner4')); $cbForumsParams->set('k20_birthdate', $pluginParams->get('sidebarBeginner2')); $cbForumsParams->set('k20_location', $pluginParams->get('sidebarBeginner3')); $cbForumsParams->set('k20_icq', $pluginParams->get('sidebarBeginner5')); $cbForumsParams->set('k20_aim', $pluginParams->get('sidebarBeginner6')); $cbForumsParams->set('k20_yim', $pluginParams->get('sidebarBeginner7')); $cbForumsParams->set('k20_msn', $pluginParams->get('sidebarBeginner8')); $cbForumsParams->set('k20_skype', $pluginParams->get('sidebarBeginner9')); $cbForumsParams->set('k20_twitter', $pluginParams->get('sidebarBeginner12')); $cbForumsParams->set('k20_facebook', $pluginParams->get('sidebarBeginner13')); $cbForumsParams->set('k20_gtalk', $pluginParams->get('sidebarBeginner10')); $cbForumsParams->set('k20_myspace', $pluginParams->get('sidebarBeginner14')); $cbForumsParams->set('k20_linkedin', $pluginParams->get('sidebarBeginner15')); $cbForumsParams->set('k20_delicious', $pluginParams->get('sidebarBeginner16')); $cbForumsParams->set('k20_digg', $pluginParams->get('sidebarBeginner18')); $cbForumsParams->set('k20_blogspot', $pluginParams->get('sidebarBeginner19')); $cbForumsParams->set('k20_flickr', $pluginParams->get('sidebarBeginner20')); $cbForumsParams->set('k20_bebo', $pluginParams->get('sidebarBeginner21')); $cbForumsParams->set('k20_website', $pluginParams->get('sidebarBeginner11')); break; case 2: $cbForumsParams->set('k20_sidebar_reg', $pluginParams->get('sidebarAdvancedExists')); $cbForumsParams->set('k20_sidebar_anon', $pluginParams->get('sidebarAdvancedPublic')); $cbForumsParams->set('k20_sidebar_del', $pluginParams->get('sidebarAdvancedDeleted')); break; } $cbForums->set('params', $cbForumsParams->asJson()); if (!$cbForums->store()) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Plugin [element] failed to migrate. Error: [error]', array('[element]' => $plugin->element, '[error]' => $cbForums->getError())) . '</div>'; } } // Migrate the forum fields to ensure their display mode is set: $query = "SELECT *" . "\n FROM " . $cbDatabase->NameQuote('#__comprofiler_fields') . "\n WHERE " . $cbDatabase->NameQuote('name') . " IN " . $cbDatabase->safeArrayOfStrings(array('forumrank', 'forumposts', 'forumkarma')); $cbDatabase->setQuery($query); $fields = $cbDatabase->loadObjectList(null, '\\CB\\Database\\Table\\FieldTable', array($cbDatabase)); /** @var $fields FieldTable[] */ foreach ($fields as $field) { $fieldParams = new Registry($field->params); switch ($field->name) { case 'forumposts': $fieldParams->set('forumStatus', 'posts'); break; case 'forumkarma': $fieldParams->set('forumStatus', 'karma'); break; case 'forumrank': $fieldParams->set('forumStatus', 'rank'); break; } $field->set('params', $fieldParams->asJson()); if (!$field->store()) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Field [name] failed to migrate. Error: [error]', array('[name]' => $field->name, '[error]' => $field->getError())) . '</div>'; } } if (!cbInstaller_uninstall_plugin($plugin, $return)) { return false; } } // Removes legacy about cb menu items from CB Menu tab params $tab = new TabTable(); if ($tab->load(17)) { $tabParams = new Registry($tab->params); if ($tabParams->get('firstSubMenuName') == '_UE_MENU_ABOUT_CB') { $tabParams->set('firstSubMenuName', ''); $tabParams->set('firstSubMenuHref', ''); if ($tabParams->get('firstMenuName') == '_UE_MENU_CB' && !$tabParams->get('secondSubMenuName')) { $tabParams->set('firstMenuName', ''); } $tab->set('params', $tabParams->asJson()); if (!$tab->store()) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Tab [title] failed to migrate. Error: [error]', array('[title]' => $tab->title, '[error]' => $tab->getError())) . '</div>'; } } } // We need to fix the name fields publish state: switch ($ueConfig['name_style']) { case 2: $nameArray = array('name' => 0, 'firstname' => 1, 'middlename' => 0, 'lastname' => 1); break; case 3: $nameArray = array('name' => 0, 'firstname' => 1, 'middlename' => 1, 'lastname' => 1); break; case 1: default: $nameArray = array('name' => 1, 'firstname' => 0, 'middlename' => 0, 'lastname' => 0); break; } foreach ($nameArray as $name => $published) { $query = 'UPDATE ' . $cbDatabase->NameQuote('#__comprofiler_fields') . "\n SET " . $cbDatabase->NameQuote('published') . " = " . (int) $published . "\n WHERE " . $cbDatabase->NameQuote('name') . " = " . $cbDatabase->Quote($name); $cbDatabase->setQuery($query); $cbDatabase->query(); } return true; }
/** * @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 string $output * @param string $formatting * @param string $reason * @param int $list_compare_types * @return mixed|null */ public function getFieldRow( &$field, &$user, $output, $formatting, $reason, $list_compare_types ) { $return = null; if ( ( ! Application::Cms()->getClientId() ) && ( $output == 'htmledit' ) && ( $reason == 'edit' ) && $user->get( 'id' ) && ( ! cbprivacyClass::checkUserModerator( $user->get( 'id' ) ) ) ) { $field->set( 'registration', 0 ); $field->set( 'profile', 0 ); $field->set( 'required', 0 ); $field->set( 'readonly', 0 ); $return = parent::getFieldRow( $field, $user, $output, $formatting, $reason, $list_compare_types ); } return $return; }
/** * 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; }
/** * If table key (id) is NULL : inserts a new row * otherwise updates existing row in the database table * * This override handles assigning orderings of new records if unset. * Can be overridden or overloaded by the child class * * @param boolean $updateNulls TRUE: null object variables are also updated, FALSE: not. * @return boolean TRUE if successful otherwise FALSE * * @throws \RuntimeException */ public function store( $updateNulls = false ) { global $_PLUGINS; $k = $this->_tbl_key; $_PLUGINS->loadPluginGroup( 'user' ); $fieldHandler = new cbFieldHandler(); // Reset the plugin id so it can be updated by _loadFieldXML $this->pluginid = null; $fieldXML = $fieldHandler->_loadFieldXML( $this ); // Rename non-system, non-calcualted, non-unique fields to ensure proper DB name structure: if ( ( ! $this->sys ) && ( ! $this->calculated ) && ( ! ( $fieldXML && ( $fieldXML->attributes( 'unique' ) == 'true' ) ) ) ) { // Always use lowercase names: $name = strtolower( $this->name ); // Replace cb prefix to be added later: $name = preg_replace( '/^cb_/', '', $name ); // Replace all invalid characters: $name = preg_replace( '/[^a-zA-Z0-9_]+/', '', $name ); // Replace duplicate underscores: $name = preg_replace( '/(_{2,})+/', '', $name ); // Replace leading underscores: $name = preg_replace( '/^_/', '', $name ); // Set the new name for this field; always: $this->name = 'cb_' . $name; if ( $this->fieldid ) { $field = new FieldTable( $this->_db ); $field->load( $this->fieldid ); // Check if existing fields name has changed: if ( $this->name != $field->name ) { $columns = $this->getTableColumns(); // Rename the database columns for this field as the name changed (we need to loop them encase it has more than 1 column like image fields): foreach ( $columns as $column ) { $this->_db->renameColumn( $this->table, $column, str_replace( $field->name, $this->name, $column ) ); } // Rebuild the tablecolumns so the field row knows about its new column names: $this->tablecolumns = implode( ',', $fieldHandler->getMainTableColumns( $this ) ); } } } // Fix HTML-editor messy addition of <p> or <div> in description which messes with translation keys: $this->description = $this->cleanEditorsTranslationJunk( $this->description ); if ( $this->$k ) { // Existing Field: Store and adapt comprofiler table using Xml description of field: $return = parent::store( $updateNulls ); if ( $return ) { $return = $fieldHandler->adaptSQL( $this, true, false, true ); } } else { // New Field: Check that there is no clash on the unique name: $query = 'SELECT COUNT(*)' . "\n FROM " . $this->_db->NameQuote( $this->_tbl ) . "\n WHERE " . $this->_db->NameQuote( 'name' ) . " = " . $this->_db->Quote( $this->name ); $this->_db->setQuery( $query ); if ( $this->_db->LoadResult() > 0 ) { $this->_error = CBTxt::T( 'THIS_FIELD_NAME_NAME_IS_ALREADY_IN_USE', 'The field name [name] is already in use!', array( '[name]' => $this->name ) ); return false; } $this->table = $fieldHandler->getMainTable( $this ); $this->tablecolumns = implode( ',', $fieldHandler->getMainTableColumns( $this ) ); if ( ( $this->tablecolumns == '' ) && ( $this->searchable == 1 ) ) { // Fields with no columns can't be searched; lets make sure it's not toggled to be searchable: $this->searchable = 0; } // This handles ordering field setting too: $return = parent::store( $updateNulls ); if ( $return ) { $return = $fieldHandler->adaptSQL( $this ); } } if ( $return && $this->$k && ( $this->_fieldvalues !== null ) ) { $fieldValues = ( is_string( $this->_fieldvalues ) ? json_decode( $this->_fieldvalues, true ) : $this->_fieldvalues ); // Delete all current field values and Insert new field values: $fieldValuesTable = new FieldValueTable( $this->_db ); $fieldValuesTable->updateFieldValues( $this->$k, $fieldValues ); } if ( ! $return ) { $this->_error = CBTxt::T( 'CLASS_STORE_FAILED_ERROR', '[class]::store failed: [error]', array( '[class]' => get_class( $this ), '[error]' => addslashes( str_replace( "\n", '\n', $this->_error . ' ' . $this->_db->getErrorMsg() ) ) ) ); return false; } else { return true; } }
function plug_cbgallery_install() { global $_CB_framework, $_CB_database; $plugin = new PluginTable(); if ( $plugin->load( array( 'element' => 'cb.profilegallery' ) ) ) { $path = $_CB_framework->getCfg( 'absolute_path' ); $indexPath = $path . '/components/com_comprofiler/plugin/user/plug_cbgallery/index.html'; $oldFilesPath = $path . '/images/comprofiler/plug_profilegallery'; $newFilesPath = $path . '/images/comprofiler/plug_cbgallery'; $query = 'SELECT *' . "\n FROM " . $_CB_database->NameQuote( '#__comprofiler_plug_profilegallery' ); $_CB_database->setQuery( $query ); $rows = $_CB_database->loadObjectList( null, '\CBLib\Database\Table\Table', array( $_CB_database, '#__comprofiler_plug_profilegallery', 'id' ) ); /** @var $rows Table[] */ foreach ( $rows as $row ) { $oldFilePath = $oldFilesPath . '/' . (int) $row->get( 'userid' ); if ( in_array( $row->get( 'pgitemtype' ), array( 'jpg', 'jpeg', 'gif', 'png' ) ) ) { $type = 'photos'; } else { $type = 'files'; } $newFilePath = $newFilesPath . '/' . (int) $row->get( 'userid' ) . '/' . $type; if ( ( ! file_exists( $oldFilePath . '/' . $row->get( 'pgitemfilename' ) ) ) || ( ( $type == 'photos' ) && ( ! file_exists( $oldFilePath . '/tn' . $row->get( 'pgitemfilename' ) ) ) ) ) { continue; } $cleanFileName = str_replace( 'pg_', '', pathinfo( $row->get( 'pgitemfilename' ), PATHINFO_FILENAME ) ); $newFileName = uniqid( $cleanFileName . '_' ) . '.' . strtolower( pathinfo( $row->get( 'pgitemfilename' ), PATHINFO_EXTENSION ) ); if ( cbReadDirectory( $newFilePath, '^' . preg_quote( $cleanFileName ) ) ) { $query = 'SELECT COUNT(*)' . "\n FROM " . $_CB_database->NameQuote( '#__comprofiler_plugin_gallery_items' ) . "\n WHERE " . $_CB_database->NameQuote( 'user_id' ) . " = " . (int) $row->get( 'userid' ) . "\n AND " . $_CB_database->NameQuote( 'value' ) . " LIKE " . $_CB_database->Quote( '%' . $_CB_database->getEscaped( $cleanFileName, true ) . '%', false ); $_CB_database->setQuery( $query ); if ( $_CB_database->loadResult() ) { continue; } } if ( ! is_dir( $newFilesPath ) ) { $oldMask = @umask( 0 ); if ( @mkdir( $newFilesPath, 0755, true ) ) { @umask( $oldMask ); @chmod( $newFilesPath, 0755 ); if ( ! file_exists( $newFilesPath . '/index.html' ) ) { @copy( $indexPath, $newFilesPath . '/index.html' ); @chmod( $newFilesPath . '/index.html', 0755 ); } } else { @umask( $oldMask ); } } if ( ! file_exists( $newFilesPath . '/.htaccess' ) ) { file_put_contents( $newFilesPath . '/.htaccess', 'deny from all' ); } if ( ! is_dir( $newFilePath ) ) { $oldMask = @umask( 0 ); if ( @mkdir( $newFilePath, 0755, true ) ) { @umask( $oldMask ); @chmod( $newFilePath, 0755 ); if ( ! file_exists( $newFilePath . '/index.html' ) ) { @copy( $indexPath, $newFilePath . '/index.html' ); @chmod( $newFilePath . '/index.html', 0755 ); } } else { @umask( $oldMask ); } } if ( ! @copy( $oldFilePath . '/' . $row->get( 'pgitemfilename' ), $newFilePath . '/' . $newFileName ) ) { continue; } else { @chmod( $newFilePath . '/' . $newFileName, 0755 ); } if ( $type == 'photos' ) { if ( ! @copy( $oldFilePath . '/tn' . $row->get( 'pgitemfilename' ), $newFilePath . '/tn' . $newFileName ) ) { continue; } else { @chmod( $newFilePath . '/tn' . $newFileName, 0755 ); } } $item = new Table( null, '#__comprofiler_plugin_gallery_items', 'id' ); $item->set( 'user_id', (int) $row->get( 'userid' ) ); $item->set( 'type', $type ); $item->set( 'value', $newFileName ); $item->set( 'folder', 0 ); $item->set( 'title', $row->get( 'pgitemtitle' ) ); $item->set( 'description', $row->get( 'pgitemdescription' ) ); $item->set( 'date', $row->get( 'pgitemdate' ) ); $item->set( 'published', ( $row->get( 'pgitemapproved', 0 ) ? (int) $row->get( 'pgitempublished', 0 ) : -1 ) ); if ( ! $item->store() ) { @unlink( $newFilePath . '/' . $newFileName ); if ( $type == 'photos' ) { @unlink( $newFilePath . '/tn' . $newFileName ); } } } $field = new FieldTable(); if ( $field->load( array( 'name' => 'cb_pgtotalquotaitems' ) ) ) { $field->set( 'type', 'integer' ); $field->set( 'tabid', 11 ); $field->set( 'pluginid', 1 ); $field->set( 'readonly', 1 ); $field->set( 'calculated', 0 ); $field->set( 'sys', 0 ); $field->store(); } $gallery = new PluginTable(); if ( $gallery->load( array( 'element' => 'cbgallery' ) ) ) { $galleryParams = new Registry( $gallery->params ); $galleryParams->set( 'photos_item_limit', 'cb_pgtotalquotaitems' ); $galleryParams->set( 'files_item_limit', 'cb_pgtotalquotaitems' ); $gallery->set( 'params', $galleryParams->asJson() ); $gallery->store(); } ob_start(); $plgInstaller = new cbInstallerPlugin(); $plgInstaller->uninstall( $plugin->id, 'com_comprofiler' ); ob_end_clean(); } }
/** * @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 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 ); }