/** * @param int $iIdAccount * * @return array */ public function getSocials($iIdAccount) { $aSocials = array(); if ($this->oConnection->Execute($this->oCommandCreator->getSocials((int) $iIdAccount))) { $oRow = null; while (false !== ($oRow = $this->oConnection->GetNextRecord())) { $oSocial = new \CSocial(); $oSocial->InitByDbRow($oRow); $aSocials[] = $oSocial; } } $this->throwDbExceptionIfExist(); return $aSocials; }
/** * @param CSocial &$oSocial * @return bool */ public function UpdateSocial(CSocial &$oSocial) { $bResult = false; try { if ($oSocial->Validate()) { if ($this->SocialExists($oSocial->Type, $oSocial->IdSocial)) { $bResult = $this->oStorage->UpdateSocial($oSocial); } } $bResult = true; } catch (CApiBaseException $oException) { $bResult = false; $this->setLastException($oException); } return $bResult; }
/** * @param string $sWhere * @return string */ protected function getSocialByWhere($sWhere) { $aMap = api_AContainer::DbReadKeys(CSocial::GetStaticMap()); $aMap = array_map(array($this, 'escapeColumn'), $aMap); $sSql = 'SELECT %s FROM %sawm_social WHERE %s'; return sprintf($sSql, implode(', ', $aMap), $this->Prefix(), $sWhere); }
public function PluginApiAppData(&$aAppData) { if (!empty(self::$sInviteEmail)) { $aAppData['ExternalInviteEmail'] = self::$sInviteEmail; } $oApiDomainsManager = \CApi::Manager('domains'); $oInput = new api_Http(); $oDomain = $oApiDomainsManager->GetDomainByUrl($oInput->GetHost()); if ($oDomain && !$oDomain->IsDefaultDomain) { $this->sTenantHash = substr(md5($oDomain->IdTenant . CApi::$sSalt), 0, 8); } \CExternalServicesConnectors::Init($aAppData, $this->sTenantHash); $oTenant = CExternalServicesConnectors::GetTenantFromCookieOrHash($this->sTenantHash); if ($oTenant) { $aSocials = $oTenant->getSocials(); $self = $this; // for PHP < 5.4 array_walk($aSocials, function ($oSocial, $sKey) use($self) { if ($oSocial->SocialAllow && in_array($sKey, $self->aEnableConnectors)) { $self->aConnectors[] = $oSocial->toArray(); } }); } if (!isset($aAppData['Plugins'])) { $aAppData['Plugins'] = array(); } $aExternalServices = array(); if (is_array($this->aConnectors)) { $aExternalServices['Connectors'] = $this->aConnectors; } $aAppData['Plugins']['ExternalServices'] = $aExternalServices; $oAccount = \api_Utils::GetDefaultAccount(); if ($oAccount) { $oApiSocial = \CApi::Manager('social'); $aSocials = $oApiSocial->getSocials($oAccount->IdAccount); $aUserServices = array(); foreach ($aSocials as $oSocial) { if ($oSocial && $oSocial instanceof \CSocial) { $aSocial = $oSocial->toArray(); $aSocial['ServiceName'] = ''; $aSocial['UserScopes'] = array(); if (in_array(strtolower($oSocial->TypeStr), $this->aEnableConnectors)) { $aUserServices[strtolower($oSocial->TypeStr)] = $aSocial; } } } $aResultUserServices = array(); foreach ($this->aConnectors as $aConnector) { $sServiceType = strtolower($aConnector['Name']); if (!$aUserServices[$sServiceType]) { $oSocial = new \CSocial(); $oSocial->TypeStr = $sServiceType; $aSocial = $oSocial->toArray(); $aUserServices[$sServiceType] = $aSocial; } $aUserServices[$sServiceType]['ServiceName'] = $aConnector['Name']; $aUserServices[$sServiceType]['UserScopes'] = array(); foreach ($aConnector['Scopes'] as $sScope) { if (trim($sScope) !== '') { $aUserServices[$sServiceType]['UserScopes'][$sScope] = in_array($sScope, $aUserServices[$sServiceType]['Scopes']); } } $aResultUserServices[$sServiceType] = $aUserServices[$sServiceType]; } $aAppData['Plugins']['ExternalServices']['Users'] = array_values($aResultUserServices); } $aAppData['AllowChangePassword'] = CApi::GetConf('plugins.external-services.allow-change-password', true); }