/** * 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; }
/** * 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; } }
/** * 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; }
/** * @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 ); } }
/** * 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 ) {} } }
/** * installs a field for plugin * * @param int $pluginId Id of the plugin creating the field * @param int $tabId Id of tab into which to install the field * @param SimpleXMLElement $field XML element of the field to install * @return int|false Field id or False on error */ function installField($pluginId, $tabId, $field) { global $_CB_database, $_PLUGINS; // Check to see if plugin tab already exists in db if (!$field->attributes('fieldid')) { $_CB_database->setQuery("SELECT fieldid FROM #__comprofiler_fields WHERE name = '" . $field->attributes('name') . "'"); $fieldid = $_CB_database->loadResult(); } else { $fieldid = $field->attributes('fieldid'); } $row = new FieldTable(); if ($fieldid) { $row->load((int) $fieldid); } $row->name = $field->attributes('name'); $row->pluginid = $pluginId; $row->tabid = $tabId; $row->type = $field->attributes('type'); $row->calculated = (int) $field->attributes('calculated'); if (!$row->fieldid) { $row->title = $field->attributes('title'); $row->description = trim($field->attributes('description')); $row->ordering = 99; $row->registration = $field->attributes('registration'); $row->profile = $field->attributes('profile'); $row->edit = $field->attributes('edit'); $row->readonly = $field->attributes('readonly'); $row->searchable = $field->attributes('searchable'); $row->params = $field->attributes('params'); } $dbTable = $field->getElementByPath('database/table'); if ($dbTable !== false) { $table = $dbTable->attributes('name'); } else { $table = $field->attributes('table'); } if ($table) { $row->table = $table; } else { $row->table = '#__comprofiler'; } // if the field type is unknown, suppose it's a field type of the plugin: $fieldTypePluginId = $_PLUGINS->getUserFieldPluginId($row->type); if (!$fieldTypePluginId) { // and register it so that the XML file for custom type can be found for store: $_PLUGINS->registerUserFieldTypes(array($row->type => 'CBfield_' . $row->type), $pluginId); } if (!$row->store()) { $this->setError(1, 'SQL error on field store2' . ': ' . $row->getError()); return false; } $fieldid = (int) $row->fieldid; return $fieldid; }
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(); } }
/** * 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 null|string|int|FieldTable[] $fields * @param string $reason * @param int $userId * @param bool $jquery * @return stdClass */ private function getFieldConditional( $fields, $reason, $userId, $jquery = false ) { global $_CB_framework; $condition = new stdClass(); $condition->show = array(); $condition->hide = array(); static $userCache = array(); if ( ! isset( $userCache[$userId] ) ) { $cbUser = CBuser::getInstance( (int) $userId, false ); $cmsUser = Application::User( (int) $userId ); $userCache[$userId] = array( $cbUser, $cbUser->getUserData(), $cmsUser->getAuthorisedViewLevels(), $cmsUser->getAuthorisedGroups() ); } /** @var CBuser $cbUser */ $cbUser = $userCache[$userId][0]; /** @var UserTable $user */ $user = $userCache[$userId][1]; /** @var array $userAccessLevels */ $userAccessLevels = $userCache[$userId][2]; /** @var array $userUsergroups */ $userUsergroups = $userCache[$userId][3]; static $fieldCache = array(); if ( ! $fields ) { /** @var FieldTable[] $tabsCache */ static $tabsCache = array(); if ( ! isset( $tabsCache[$user->id] ) ) { $cbTabs = $cbUser->_getCbTabs(); $tabsCache[$user->id] = $cbTabs->_getTabFieldsDb( null, $user, 'adminfulllist', null, true, true ); } $fields = $tabsCache[$user->id]; } elseif ( ! is_array( $fields ) ) { if ( is_string( $fields ) || is_integer( $fields ) ) { $fieldId = (int) $fields; if ( $fieldId ) { if ( ! isset( $fieldCache[$fieldId] ) ) { $field = new FieldTable(); $field->load( $fieldId ); $fieldCache[$fieldId] = $field; } $fields = $fieldCache[$fieldId]; } } $fields = array( $fields ); } elseif ( is_array( $fields ) ) { $fieldArray = array(); foreach ( $fields as $fieldId ) { if ( is_string( $fieldId ) || is_integer( $fieldId ) ) { $fieldId = (int) $fieldId; if ( $fieldId ) { if ( ! isset( $fieldCache[$fieldId] ) ) { $field = new FieldTable(); $field->load( $fieldId ); $fieldCache[$fieldId] = $field; } $fieldArray[] = $fieldCache[$fieldId]; } } elseif ( $fieldId instanceof FieldTable ) { $fieldArray[] = $fieldId; } } $fields = $fieldArray; } /** @var Registry[] $fieldParams */ static $fieldParams = array(); /** @var array[] $conditioned */ static $conditioned = array(); $uId = (int) $user->get( 'id' ); if ( $fields ) foreach ( $fields as $field ) { if ( $field instanceof FieldTable ) { $fId = (int) $field->get( 'fieldid' ); if ( ! isset( $conditioned[$fId][$uId][$reason][$jquery] ) ) { $fieldConditions = array(); $conditioned[$fId][$uId][$reason][$jquery] = $fieldConditions; if ( ! isset( $fieldParams[$fId] ) ) { if ( ! ( $field->params instanceof ParamsInterface ) ) { $field->params = new Registry( $field->params ); } $fieldParams[$fId] = $field->params; } $params = $fieldParams[$fId]; for ( $i = 1; $i <= 5; $i++ ) { $conditional = ( $i > 1 ? $i : null ); $display = (int) $params->get( 'cbconditional_display' . $conditional, 0 ); if ( $reason == 'register' ) { if ( ! $params->get( 'cbconditional_target_reg' . $conditional, 1 ) ) { $display = 0; } } elseif ( $reason == 'edit' ) { if ( ! $params->get( 'cbconditional_target_edit' . $conditional, 1 ) ) { $display = 0; } } elseif ( $reason == 'profile' ) { if ( ! $params->get( 'cbconditional_target_view' . $conditional, 1 ) ) { $display = 0; } } elseif ( $reason == 'search' ) { if ( ! $params->get( 'cbconditional_target_search' . $conditional, 0 ) ) { $display = 0; } } elseif ( $reason == 'list' ) { if ( ! $params->get( 'cbconditional_target_list' . $conditional, 1 ) ) { $display = 0; } } if ( $display ) { if ( $display == 2 ) { $mode = (int) $params->get( 'cbconditional_mode' . $conditional, 0 ); $show = $this->getFieldsArray( ( $mode == 1 ? $fId : null ) ); $hide = $this->getFieldsArray( ( $mode == 0 ? $fId : null ) ); $optshow = array(); $opthide = array(); $fieldPair = explode( ',', $params->get( 'cbconditional_field' . $conditional, null ) ); if ( count( $fieldPair ) < 2 ) { array_unshift( $fieldPair, 0 ); } $fieldId = (int) array_shift( $fieldPair ); $fieldName = array_pop( $fieldPair ); if ( ! isset( $fields[$fieldId] ) ) { $field = new FieldTable(); $field->load( $fieldId ); $fields[$fieldId] = $field; } $fieldObj = $fields[$fieldId]; } else { $show = $this->getFieldsArray( $params->get( 'cbconditional_show' . $conditional, null ) ); $hide = $this->getFieldsArray( $params->get( 'cbconditional_hide' . $conditional, null ) ); $optshow = $this->getFieldsArray( $params->get( 'cbconditional_options_show' . $conditional, null ) ); $opthide = $this->getFieldsArray( $params->get( 'cbconditional_options_hide' . $conditional, null ) ); $fieldId = (int) $field->get( 'fieldid' ); $fieldName = $field->get( 'name' ); $fieldObj = $field; } if ( $show || $hide || $optshow || $opthide ) { $operator = (int) $params->get( 'cbconditional_operator' . $conditional, 0 ); $value = $cbUser->replaceUserVars( $params->get( 'cbconditional_value' . $conditional, null ), false, true, $this->getExtras(), ( (int) $params->get( 'cbconditional_value_translate' . $conditional, 0 ) ? true : false ) ); if ( in_array( $operator, array( 6, 7 ) ) ) { $value = null; } switch ( $fieldName ) { case 'customvalue': $fieldValue = $cbUser->replaceUserVars( $params->get( 'cbconditional_customvalue' . $conditional, null ), false, true, $this->getExtras(), ( (int) $params->get( 'cbconditional_customvalue_translate' . $conditional, 0 ) ? true : false ) ); break; case 'customviewaccesslevels': $accessLevels = cbToArrayOfInt( explode( '|*|', $params->get( 'cbconditional_customviewaccesslevels' . $conditional, null ) ) ); $fieldValue = 0; foreach ( $accessLevels as $accessLevel ) { if ( in_array( $accessLevel, $userAccessLevels ) ) { $fieldValue = 1; break; } } $operator = 0; $value = 1; break; case 'customusergroups': $userGroups = cbToArrayOfInt( explode( '|*|', $params->get( 'cbconditional_customusergroups' . $conditional, null ) ) ); $fieldValue = 0; foreach ( $userGroups as $userGroup ) { if ( in_array( $userGroup, $userUsergroups ) ) { $fieldValue = 1; break; } } $operator = 0; $value = 1; break; default: $fieldValue = $this->getFieldValue( $user, $cbUser, $fieldObj, $reason ); break; } if ( $jquery ) { $_CB_framework->addJQueryPlugin( 'cbcondition', '/components/com_comprofiler/plugin/user/plug_cbconditional/js/cbcondition.js' ); $js = "var conditionShow = [];" . "var conditionHide = [];"; foreach ( $show as $v ) { $js .= "conditionShow.push( '#cbfr_$v,#cbfr_" . $v . "__verify,#cbfrd_$v,#cbfrd_" . $v . "__verify' );"; } foreach ( $hide as $k => $v ) { $js .= "conditionHide.push( '#cbfr_$v,#cbfr_" . $v . "__verify,#cbfrd_$v,#cbfrd_" . $v . "__verify' );"; } foreach ( $optshow as $k => $v ) { $js .= "conditionShow.push( '#cbf$v' );"; } foreach ( $opthide as $k => $v ) { $js .= "conditionHide.push( '#cbf$v' );"; } switch ( $fieldName ) { case 'customvalue': case 'customviewaccesslevels': case 'customusergroups': $js .= "$.cbcondition({" . "conditions: [{" . "operator: " . (int) $operator . "," . "input: '" . addslashes( str_replace( array( "\n", "\r" ), array( "\\n", "\\r" ), ( is_array( $fieldValue ) ? implode( '|*|', $fieldValue ) : $fieldValue ) ) ) . "'," . "value: '" . addslashes( str_replace( array( "\n", "\r" ), array( "\\n", "\\r" ), ( is_array( $value ) ? implode( '|*|', $value ) : $value ) ) ) . "'," . "show: conditionShow," . "hide: conditionHide," . "reset: " . (int) $this->params->get( 'cond_reset', 0 ) . "" . "}]" . "});"; break; default: $js .= "$( '#cbfr_" . (int) $fieldId . ",#cbfrd_" . (int) $fieldId . "' ).cbcondition({" . "conditions: [{" . "operator: " . (int) $operator . "," . "input: '" . addslashes( str_replace( array( "\n", "\r" ), array( "\\n", "\\r" ), ( is_array( $fieldValue ) ? implode( '|*|', $fieldValue ) : $fieldValue ) ) ) . "'," . "value: '" . addslashes( str_replace( array( "\n", "\r" ), array( "\\n", "\\r" ), ( is_array( $value ) ? implode( '|*|', $value ) : $value ) ) ) . "'," . "show: conditionShow," . "hide: conditionHide," . "reset: " . (int) $this->params->get( 'cond_reset', 0 ) . "" . "}]" . "});"; break; } $_CB_framework->outputCbJQuery( $js, 'cbcondition' ); } $fieldConditions[] = array( 'match' => $this->getMatch( $fieldValue, $operator, $value ), 'show' => $show, 'hide' => $hide ); } } } $conditioned[$fId][$uId][$reason][$jquery] = $fieldConditions; } $conditions = $conditioned[$fId][$uId][$reason][$jquery]; foreach ( $conditions as $cond ) { if ( $cond['match'] ) { foreach ( $cond['show'] as $v ) { $v = (int) $v; if ( in_array( $v, $condition->hide ) ) { unset( $condition->hide[$v] ); } if ( ! in_array( $v, $condition->show ) ) { array_push( $condition->show, $v ); } } foreach ( $cond['hide'] as $v ) { $v = (int) $v; if ( in_array( $v, $condition->show ) ) { unset( $condition->show[$v] ); } if ( ! in_array( $v, $condition->hide ) ) { array_push( $condition->hide, $v ); } } } else { foreach ( $cond['show'] as $v ) { $v = (int) $v; if ( in_array( $v, $condition->show ) ) { unset( $condition->show[$v] ); } if ( ! in_array( $v, $condition->hide ) ) { array_push( $condition->hide, $v ); } } foreach ( $cond['hide'] as $v ) { $v = (int) $v; if ( in_array( $v, $condition->hide ) ) { unset( $condition->hide[$v] ); } if ( ! in_array( $v, $condition->show ) ) { array_push( $condition->show, $v ); } } } } } } return $condition; }
/** * @param FieldTable|int $field * @return bool */ static public function checkFieldEditAccess( $field ) { if ( self::checkUserModerator() ) { return true; } static $fields = array(); static $cache = array(); if ( is_integer( $field ) ) { if ( ! isset( $fields[$field] ) ) { $loadedField = new FieldTable(); $loadedField->load( $field ); $fields[$field] = $loadedField; } $field = $fields[$field]; } $return = true; if ( $field instanceof FieldTable ) { $myId = Application::MyUser()->getUserId(); $fieldId = (int) $field->get( 'fieldid' ); if ( ! isset( $cache[$fieldId][$myId] ) ) { $authorized = true; $tabId = (int) $field->get( 'tabid' ); if ( ! ( $field->params instanceof ParamsInterface ) ) { $field->params = new Registry( $field->params ); } $display = $field->params->get( 'cbprivacy_edit', '0' ); if ( ( $display == 1 ) || ( ( $display == 2 ) && ( ! self::checkUserModerator() ) ) || ( ( $display == 3 ) && ( ! Application::MyUser()->canViewAccessLevel( $field->params->get( 'cbprivacy_edit_access', '1' ) ) ) ) ) { $authorized = false; } if ( $authorized && ( ! cbprivacyClass::checkTabEditAccess( $tabId ) ) ) { $authorized = false; } $cache[$fieldId][$myId] = $authorized; } $return = $cache[$fieldId][$myId]; } return $return; }
/** * 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; }