/** * Save Token * * @return */ public function saveToken($params = array()) { $token = $this->_objPlugin->getUserAccessToken(); if ($token) { $this->_objPlugin->setAccessToken($token); $token_extended = $this->_objPlugin->setExtendedAccessToken(); if ($token_extended) { $token = $token_extended; } $this->_objPlugin->setAccessToken($token); $this->_me = $this->_objPlugin->api('/me'); $user_id = OW::getUser()->getId(); if ($user_id > 0) { //get token old if exists $params = array('service' => $this->_plugin, 'userId' => $user_id); // YNSOCIALBRIDGE_BOL_Token $tokenDto = $this->getToken($params); if (!$tokenDto) { //save new Token $tokenDto = new YNSOCIALBRIDGE_BOL_Token(); $tokenDto->service = $this->_plugin; $tokenDto->userId = $user_id; } $tokenDto->accessToken = $token; $tokenDto->uid = $this->getOwnerId(); $tokenDto->timestamp = time(); YNSOCIALBRIDGE_BOL_TokenService::getInstance()->save($tokenDto); } } }
/** * Save Token * * @return */ public function saveToken($params = array()) { $user_id = OW::getUser()->getId(); if ($user_id > 0) { //get token old if exists $params = array('service' => $this->_plugin, 'userId' => $user_id); // YNSOCIALBRIDGE_BOL_Token $tokenDto = $this->getToken($params); if (!$tokenDto) { //save new Token $tokenDto = new YNSOCIALBRIDGE_BOL_Token(); $tokenDto->service = $this->_plugin; $tokenDto->userId = $user_id; } $tokenDto->accessToken = $_SESSION['socialbridge_session'][$this->_plugin]['access_token']; $tokenDto->secretToken = $_SESSION['socialbridge_session'][$this->_plugin]['secret_token']; $tokenDto->uid = $this->getOwnerId(); $tokenDto->timestamp = time(); YNSOCIALBRIDGE_BOL_TokenService::getInstance()->save($tokenDto); } }
public function queueProcess() { $queues = YNSOCIALBRIDGE_BOL_QueueService::getInstance()->getAllQueues(); $core = new YNSOCIALBRIDGE_CLASS_Core(); foreach ($queues as $queue) { switch ($queue->type) { case 'sendInvite': $extra_params = unserialize($queue->extraParams); $token = YNSOCIALBRIDGE_BOL_TokenService::getInstance()->findById($queue->tokenId); $obj = $core->getInstance($queue->service); $params['list'] = $extra_params['list']; $params['link'] = $extra_params['link']; $params['message'] = $extra_params['message']; $params['uid'] = $token->uid; $params['user_id'] = $queue->userId; $params['access_token'] = $token->accessToken; $params['secret_token'] = $token->secretToken; echo ucfirst($queue->service) . ": " . $token->uid . ": Send invite successfully! "; if ($obj->sendInvites($params)) { echo " <br/> "; YNSOCIALBRIDGE_BOL_QueueService::getInstance()->delete($queue); } break; case 'getFeed': $configs = OW::getConfig()->getValues('ynsocialstream'); if (isset($configs['get_feed_cron']) && $configs['get_feed_cron']) { $service = $queue->service; $token = YNSOCIALBRIDGE_BOL_TokenService::getInstance()->findById($queue->tokenId); //get user & check authorized get feed OW_User::getInstance()->login($token->userId); if (!OW::getUser()->isAuthorized('ynsocialstream', 'get_feed')) { break; } //check preferences if (!$configs['enable_' . $service . '_' . $token->userId]) { break; } if ($token && isset($configs['cron_job_user_' . $token->userId]) && $configs['cron_job_user_' . $token->userId]) { $uid = $token->uid; //get Feeds $obj = $core->getInstance($service); $feedService = YNSOCIALSTREAM_BOL_SocialstreamFeedService::getInstance(); $feedLast = $feedService->getFeedLast($service, $uid); $arr_token = array('access_token' => $token->accessToken, 'secret_token' => $token->secretToken); $arr_token['lastFeedTimestamp'] = 0; if ($feedLast) { $arr_token['lastFeedTimestamp'] = $feedLast['timestamp']; } $arr_token['limit'] = $configs['max_' . $service . '_get_feed']; $arr_token['uid'] = $uid; $arr_token['type'] = 'user'; $activities = $obj->getActivity($arr_token); if ($activities != null) { $obj->insertFeeds(array('activities' => $activities, 'user_id' => $token->userId, 'timestamp' => $arr_token['lastFeedTimestamp'], 'access_token' => $token->accessToken, 'secret_token' => $token->secretToken, 'uid' => $uid)); } $queue->lastRun = date('Y-m-d H:i:s'); YNSOCIALBRIDGE_BOL_QueueService::getInstance()->save($queue); echo ucfirst($service) . ": " . $token->uid . ": Get feed successfully!"; echo " <br/> "; } OW_User::getInstance()->logout(); } break; default: break; } } }
public function getToken($params = array()) { return YNSOCIALBRIDGE_BOL_TokenService::getInstance()->findUserToken($params); }
public function disconnect() { $serviceName = $_REQUEST['service']; $core = new YNSOCIALBRIDGE_CLASS_Core(); //clear session if (isset($_SESSION['socialbridge_session'][$serviceName])) { unset($_SESSION['socialbridge_session'][$serviceName]); } //remove token $obj = $core->getInstance($serviceName); $values = array('service' => $serviceName, 'userId' => OW::getUser()->getId()); $tokenDto = $obj->getToken($values); if ($tokenDto) { YNSOCIALBRIDGE_BOL_TokenService::getInstance()->delete($tokenDto); } $this->redirect(OW::getRouter()->urlForRoute('ynsocialbridge-connects')); }
public function linking($params) { if (!OW::getUser()->isAuthenticated()) { $this->redirect(OW_URL_HOME); //throw new AuthenticateException(); } if (!isset($params['service']) || !strlen(trim($params['service']))) { $this->redirect(OW_URL_HOME); //throw new Redirect404Exception(); } // init $oBridge = YNSOCIALCONNECT_CLASS_SocialBridge::getInstance(); $sService = isset($params['service']) ? strtolower($params['service']) : null; $sIdentity = null; $data = NULL; $type = 'bridge'; $sUrlRedirect = OW::getRouter()->urlForRoute('ynsocialconnect_user_user_linking'); // process if ($oBridge->hasProvider($sService)) { // process Facebook, Twitter, LinkedIn $profile = null; //check enable API $clientConfig = YNSOCIALBRIDGE_BOL_ApisettingService::getInstance()->getConfig($sService); if ($clientConfig) { $core = new YNSOCIALBRIDGE_CLASS_Core(); $oProvider = $core->getInstance($sService); if (!empty($_SESSION['socialbridge_session'][$sService])) { try { $profile = $oProvider->getOwnerInfo($_SESSION['socialbridge_session'][$sService]); } catch (Exception $e) { $profile = null; } } // if ($profile) { $sIdentity = isset($profile['identity']) ? $profile['identity'] : null; //// filter data $profile = YNSOCIALCONNECT_CLASS_SocialConnect::getInstance()->filterProfile($profile, $sService); $data = $profile; } } } else { // process with other services $type = 'not_bridge'; $sIdentity = isset($_REQUEST['identity']) ? $_REQUEST['identity'] : null; $data = $_REQUEST; } if (NULL == $sIdentity) { $type = 'close_not_loading'; } else { //// update ow_base_remote_auth $authAdapter = new YNSOCIALCONNECT_CLASS_AuthAdapter($sIdentity, $sService); $authAdapter->register(OW::getUser()->getId()); //// update agent table in social connect $provider = YNSOCIALCONNECT_BOL_ServicesService::getInstance()->getProvider($sService); $entity = new YNSOCIALCONNECT_BOL_Agents(); $entity->userId = (int) OW::getUser()->getId(); $entity->identity = $sIdentity; $entity->serviceId = $provider->id; $entity->ordering = 0; $entity->status = 'linking'; $entity->login = '******'; $entity->data = base64_encode(serialize($data)); $entity->tokenData = base64_encode(serialize($data)); $entity->token = time(); $entity->createdTime = time(); $entity->loginTime = time(); $entity->logoutTime = time(); YNSOCIALCONNECT_BOL_AgentsService::getInstance()->save($entity); //// delete old token and add new token in social bridge if ($oBridge->hasProvider($sService)) { // remove old token $values = array('service' => $sService, 'userId' => OW::getUser()->getId()); $tokenDto = $oProvider->getToken($values); if ($tokenDto) { YNSOCIALBRIDGE_BOL_TokenService::getInstance()->delete($tokenDto); } // add new token $oProvider->saveToken(); } //// add user linking $entityUserlinking = new YNSOCIALCONNECT_BOL_Userlinking(); $entityUserlinking->userId = (int) OW::getUser()->getId(); $entityUserlinking->identity = $sIdentity; $entityUserlinking->serviceId = $provider->id; YNSOCIALCONNECT_BOL_UserlinkingService::getInstance()->save($entityUserlinking); } // end //// clear session if (isset($_SESSION['socialbridge_session'][$sService])) { unset($_SESSION['socialbridge_session'][$sService]); } $this->assign('type', $type); $this->assign('sUrlRedirect', $sUrlRedirect); }