static function r_implode($glue, $pieces) { foreach ($pieces as $r_pieces) { if (is_array($r_pieces)) { unset($r_pieces['id']); // Remove id key which is useless to import $retVal[] = SCStringUtilities::r_implode($glue, $r_pieces); } else { $retVal[] = trim($r_pieces); } } return implode($glue, $retVal); }
protected function importSocialProfile() { $fieldMap = $this->getFieldMap($this->network); $socialProfile = $this->fetchProfileFromFieldMap(true); if ($socialProfile) { foreach ($fieldMap as $fieldId => $socialField) { // Fetch the value from the POST data (if present) or the imported data from the Social Network $value = $socialProfile->getFieldWithUserState($fieldId); if ($value != null && $value != "") { if (is_array($value)) { // This is a field with multiple, comma separated values // Remove empty values to prevent blah, , blah as output unset($value['id']); // Remove id key which is useless to import $value = SCStringUtilities::r_implode(', ', $value); } $this->saveProfileField($fieldId, $value); } } } }
function get($path, $default = null) { $data = $default; $pageListTypes = array("music", "books", "movies", "television", "games", "activities", "interests"); if (in_array($path, $pageListTypes)) { $data = $this->formatPageList(parent::get($path, $default)); } else { if ($this->exists($path)) { $data = parent::get($path, $default); } else { if ($path == "full_name") { // standardized provider value for full name $data = parent::get('name', $default); } else { // Alternative fields that require extra parsing $parts = explode('.', $path); if ($parts[0] == 'education') { if (isset($this->data->education)) { $edu = $this->data->education; if ($edu) { foreach ($edu as $k => $node) { if ($node->type == $parts[1]) { unset($parts[0]); unset($parts[1]); $newPath = 'education.' . $k . '.' . implode('.', $parts); $data = parent::get($newPath, $default); break; } } } } } else { return $default; } } } } if (!empty($data)) { if (is_array($data)) { // This is a field with multiple, comma separated values // Remove empty values to prevent blah, , blah as output unset($data['id']); // Remove id key which is useless to import $data = SCStringUtilities::r_implode(', ', $data); } // add custom field handlers here switch ($path) { case 'website': $websites = explode("\n", $data); if (count($websites) > 0) { $data = trim($websites[0]); } break; } } return $data; }
function migrateSocialFieldsToProfile($joomlaId) { $socialFieldMap = $this->configModel->getSetting('profiles_' . $this->profileName . "_field_map"); $fields = array(); foreach ($socialFieldMap as $socialField) { // Strip out any path information from the field $loc = strpos($socialField, '.'); if ($loc) { $socialField = substr($socialField, 0, $loc); } $fields[] = $socialField; } $fields = array_unique($fields); $socialProfile = $this->fetchProfile($fields); $sql = ""; if ($socialProfile) { foreach ($socialFieldMap as $fieldId => $socialField) { $value = $socialProfile->get($socialField); if ($value != null && $value != "") { if (is_array($value)) { // This is a field with multiple, comma separated values // Remove empty values to prevent blah, , blah as output unset($value['id']); // Remove id key which is useless to import $value = SCStringUtilities::r_implode(', ', $value); } $sql .= $this->addFieldToDB($joomlaId, $fieldId, $value); } } } $this->_db->setQuery($sql); $this->_db->queryBatch(); }