Exemple #1
0
 /**
  * Returns class instance
  *
  * @return YNSOCIALBRIDGE_BOL_ApisettingService
  */
 public static function getInstance()
 {
     if (!isset(self::$classInstance)) {
         self::$classInstance = new self();
     }
     return self::$classInstance;
 }
Exemple #2
0
function socialbridge_add_admin_notification(BASE_CLASS_EventCollector $e)
{
    $language = OW::getLanguage();
    $fbConfig = YNSOCIALBRIDGE_BOL_ApisettingService::getInstance()->getConfig('facebook');
    $twConfig = YNSOCIALBRIDGE_BOL_ApisettingService::getInstance()->getConfig('twitter');
    $liConfig = YNSOCIALBRIDGE_BOL_ApisettingService::getInstance()->getConfig('linkedin');
    if (!$fbConfig || !$twConfig || !$liConfig) {
        $e->add($language->text('ynsocialbridge', 'requires_configuration_message', array('settingsUrl' => OW::getRouter()->urlForRoute('ynsocialbridge-admin'))));
    }
}
Exemple #3
0
 function checkSocialBridgePlugin($provider)
 {
     if (!($plugin = BOL_PluginService::getInstance()->findPluginByKey('ynsocialbridge'))) {
         return false;
     } else {
         if (!$plugin->isActive() || !YNSOCIALBRIDGE_BOL_ApisettingService::getInstance()->getConfig($provider)) {
             return false;
         }
     }
     return true;
 }
Exemple #4
0
function ynsocialpublisher_on_entity_add(OW_Event $event)
{
    $params = $event->getParams();
    $data = $event->getData();
    $pluginKey = $params['pluginKey'];
    $entityType = $params['entityType'];
    $entityId = $params['entityId'];
    $userId = $params['userId'];
    $service = YNSOCIALPUBLISHER_BOL_Service::getInstance();
    $userSetting = $service->getUsersetting($userId, $pluginKey);
    $supportedPluginType = YNSOCIALPUBLISHER_CLASS_Core::getInstance()->getTypesByPluginKey($pluginKey);
    $count = 0;
    foreach (array('facebook', 'twitter', 'linkedin') as $serviceName) {
        if (YNSOCIALBRIDGE_BOL_ApisettingService::getInstance()->getConfig($serviceName)) {
            $count++;
        }
    }
    /*
     * Must check:
     * _ Setting is available
     * _ At least one provider is available
     * _ Option is not 'Do not ask me again' (2)
     */
    if (!empty($userSetting) && count($userSetting['providers']) > 0 && in_array($entityType, $supportedPluginType) && $count) {
        $providers = $userSetting['providers'];
        if ($userSetting['option'] == YNSOCIALPUBLISHER_BOL_UsersettingDao::OPTIONS_ASK) {
            if ($pluginKey == 'newsfeed') {
                $params = implode(';', array($entityId, $userId));
                setcookie('ynsocialpublisher_feed_data_' . $entityId, $params, time() + 300, '/');
            } else {
                $_SESSION[YNSOCIALPUBLISHER_SESSION_DATA] = implode(';', array($pluginKey, $entityType, $entityId));
            }
        } elseif ($userSetting['option'] == YNSOCIALPUBLISHER_BOL_UsersettingDao::OPTIONS_AUTO) {
            // auto publish to selected providers
            $core = YNSOCIALPUBLISHER_CLASS_Core::getInstance();
            $language = OW::getLanguage();
            $status = $core->getDefaultStatus($pluginKey, $entityType, $entityId);
            $postData = $core->getPostData($pluginKey, $entityId, $entityType, $providers, $status);
            $coreBridge = new YNSOCIALBRIDGE_CLASS_Core();
            foreach ($providers as $provider) {
                $clientConfig = YNSOCIALBRIDGE_BOL_ApisettingService::getInstance()->getConfig($provider);
                if ($clientConfig && isset($postData[$provider])) {
                    $obj = $coreBridge->getInstance($provider);
                    try {
                        $obj->postActivity($postData[$provider]);
                    } catch (Exception $e) {
                        //echo $e->getMessage();
                    }
                }
            }
        }
    }
}
Exemple #5
0
 public function checkFacebookApp()
 {
     $name = 'facebook';
     $fbSettings = YNSOCIALBRIDGE_BOL_ApisettingService::getInstance()->getConfig($name);
     if (!is_object($fbSettings)) {
         return false;
     }
     $api_params = unserialize($fbSettings->apiParams);
     $appId = $api_params['key'];
     $secret = $api_params['secret'];
     if ($appId && $secret) {
         return true;
     }
     return false;
 }
Exemple #6
0
 public function initSetting()
 {
     $facebook = YNSOCIALBRIDGE_BOL_ApisettingService::getInstance()->getConfig('facebook');
     if (isset($facebook) && NULL != $facebook) {
         $this->providers['facebook'] = TRUE;
     } else {
         $this->providers['facebook'] = FALSE;
     }
     $twitter = YNSOCIALBRIDGE_BOL_ApisettingService::getInstance()->getConfig('twitter');
     if (isset($twitter) && NULL != $twitter) {
         $this->providers['twitter'] = TRUE;
     } else {
         $this->providers['twitter'] = FALSE;
     }
     $linkedin = YNSOCIALBRIDGE_BOL_ApisettingService::getInstance()->getConfig('linkedin');
     if (isset($linkedin) && NULL != $linkedin) {
         $this->providers['linkedin'] = TRUE;
     } else {
         $this->providers['linkedin'] = FALSE;
     }
 }
Exemple #7
0
 public function index($params)
 {
     //	init
     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();
     }
     $oBridge = YNSOCIALCONNECT_CLASS_SocialBridge::getInstance();
     //	process
     $sService = isset($params['service']) ? strtolower($params['service']) : null;
     $type = 'bridge';
     $sIdentity = null;
     $data = NULL;
     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);
             $values = array('service' => $sService, 'userId' => OW::getUser()->getId());
             $tokenDto = $oProvider->getToken($values);
             if (!empty($_SESSION['socialbridge_session'][$sService])) {
                 try {
                     $profile = $oProvider->getOwnerInfo($_SESSION['socialbridge_session'][$sService]);
                 } catch (Exception $e) {
                     $profile = null;
                 }
             } else {
                 if ($tokenDto) {
                     $profile = $oProvider->getOwnerInfo(array('access_token' => $tokenDto->accessToken, 'secret_token' => $tokenDto->secretToken, 'user_id' => $tokenDto->uid));
                 }
             }
             //
             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;
     }
     $provider = YNSOCIALCONNECT_BOL_ServicesService::getInstance()->getProvider($sService);
     $aUser = YNSOCIALCONNECT_BOL_AgentsService::getInstance()->getUserByIdentityAndService($sIdentity, $sService, $provider->id, $data);
     $sUrlRedirect = '';
     if (NULL == $aUser && NULL == $sIdentity) {
         if ($oBridge->hasProvider($sService)) {
             $type = 'close_not_loading';
             $this->assign('type', $type);
             $this->assign('sUrlRedirect', $sUrlRedirect);
         }
     }
     if ($aUser) {
         //	login again
         //	logining which happen in YNSOCIALCONNECT_BOL_AgentsDao after execute checkExistingAgent
         //	now, redirect by url in session
         // @formatter:off
         if (isset($_SESSION['ynsc_session']) && isset($_SESSION['ynsc_session']['urlRedirect']) && strlen(trim($_SESSION['ynsc_session']['urlRedirect'])) > 0) {
             $sUrlRedirect = $_SESSION['ynsc_session']['urlRedirect'];
         } else {
             $sUrlRedirect = OW_URL_HOME;
         }
         // @formatter:on
         //	update login statistic
         YNSOCIALCONNECT_BOL_ServicesService::getInstance()->updateStatistics($sService, 'login');
     } else {
         //	sign up now
         //	saved data to session
         try {
             OW::getSession()->set(self::SESSION_SIGNUP_DATA, array('service' => $sService, 'identity' => $sIdentity, 'user' => $data));
         } catch (Exception $e) {
         }
         $sUrlRedirect = OW::getRouter()->urlForRoute('base_join');
         //	mapping profile in session
         $questions = $this->__mappingProfile($data, $sService);
         //	update later signup statistic in quick signup
         //	check existed user by email
         $checkExist = false;
         $checkEmail = false;
         if (isset($data['email'])) {
             $email = $data['email'];
             $aUser = BOL_UserService::getInstance()->findByEmail($email);
             if ($aUser) {
                 //	redirect to synchronize page
                 $sUrlRedirect = OW::getRouter()->urlFor('YNSOCIALCONNECT_CTRL_UserSync', 'index');
                 $checkExist = true;
             }
             if ($data['email']) {
                 $checkEmail = true;
             }
         }
         $plugin = OW::getPluginManager()->getPlugin('ynsocialconnect');
         $key = strtolower($plugin->getKey());
         if (!OW::getConfig()->getValue($key, 'signup_mode') && !$checkExist && $checkEmail && $questions['username']) {
             $username = $questions['username'];
             $password = uniqid();
             $user = BOL_UserService::getInstance()->createUser($username, $password, $questions['email'], null, true);
             BOL_QuestionService::getInstance()->saveQuestionsData(array_filter($questions), $user->id);
             OW_User::getInstance()->login($user->id);
             $event = new OW_Event(OW_EventManager::ON_USER_REGISTER, array('userId' => $user->id, 'quick_signup' => true));
             OW::getEventManager()->trigger($event);
             $sUrlRedirect = OW_URL_HOME;
         }
     }
     $this->assign('type', $type);
     $this->assign('sUrlRedirect', $sUrlRedirect);
     // 	end
 }
Exemple #8
0
 public function index($params)
 {
     if (!OW::getUser()->isAuthenticated()) {
         throw new AuthenticateException();
     }
     $el = $this->menu->getElement('connects');
     if ($el) {
         $el->setActive(true);
     }
     //get callback URL
     $callbackUrl = OW::getRouter()->urlForRoute('ynsocialbridge-connects');
     $core = new YNSOCIALBRIDGE_CLASS_Core();
     $arrObjServices = array();
     foreach (array('facebook', 'twitter', 'linkedin') as $serviceName) {
         //check enable API
         $clientConfig = YNSOCIALBRIDGE_BOL_ApisettingService::getInstance()->getConfig($serviceName);
         if ($clientConfig->apiParams) {
             $params = unserialize($clientConfig->apiParams);
             if (!$params['key'] || !$params['secret']) {
                 continue;
             }
             $obj = $core->getInstance($serviceName);
             $values = array('service' => $serviceName, 'userId' => OW::getUser()->getId());
             $tokenDto = $obj->getToken($values);
             $profile = null;
             $connect_url = "";
             $disconnect_url = OW::getRouter()->urlForRoute('ynsocialbridge-disconnect') . "?service=" . $serviceName;
             if ($tokenDto) {
                 if ($serviceName == 'facebook') {
                     $permissions = $obj->hasPermission(array('uid' => $tokenDto->uid, 'access_token' => $tokenDto->accessToken));
                     if ($permissions) {
                         $profile = @$obj->getOwnerInfo(array('access_token' => $tokenDto->accessToken, 'secret_token' => $tokenDto->secretToken, 'user_id' => $tokenDto->uid));
                         $_SESSION['socialbridge_session']['facebook']['access_token'] = $tokenDto->accessToken;
                     } else {
                         YNSOCIALBRIDGE_BOL_TokenService::getInstance()->delete($tokenDto);
                         $scope = "email,user_about_me,user_birthday,user_hometown,user_interests,user_location,user_photos,user_website";
                         $connect_url = $obj->getConnectUrl() . "?scope=" . $scope . "&" . http_build_query(array('callbackUrl' => $callbackUrl));
                     }
                 } else {
                     $profile = @$obj->getOwnerInfo(array('access_token' => $tokenDto->accessToken, 'secret_token' => $tokenDto->secretToken, 'user_id' => $tokenDto->uid));
                     $_SESSION['socialbridge_session'][$serviceName]['access_token'] = $tokenDto->accessToken;
                     $_SESSION['socialbridge_session'][$serviceName]['secret_token'] = $tokenDto->secretToken;
                     $_SESSION['socialbridge_session'][$serviceName]['user_id'] = $tokenDto->uid;
                 }
             } else {
                 $scope = "";
                 switch ($serviceName) {
                     case 'facebook':
                         $scope = "email,user_about_me,user_birthday,user_hometown,user_interests,user_location,user_photos,user_website";
                         break;
                     case 'twitter':
                         $scope = "";
                         break;
                     case 'linkedin':
                         $scope = "r_basicprofile,rw_nus,r_network,w_messages";
                         break;
                 }
                 $connect_url = $obj->getConnectUrl() . "?scope=" . $scope . "&" . http_build_query(array('callbackUrl' => $callbackUrl));
             }
             $objService['serviceName'] = $serviceName;
             $objService['connectUrl'] = $connect_url;
             $objService['disconnectUrl'] = $disconnect_url;
             $objService['profile'] = $profile;
             $objService['logo'] = OW::getPluginManager()->getPlugin('ynsocialbridge')->getStaticUrl() . "img/" . $serviceName . ".jpg";
             $arrObjServices[] = $objService;
         }
     }
     //assign to view page
     $this->assign('arrObjServices', $arrObjServices);
     $this->assign('noImageUrl', OW::getPluginManager()->getPlugin('ynsocialbridge')->getStaticUrl() . "img/default_user.jpg");
 }
Exemple #9
0
 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);
 }
Exemple #10
0
 /**
  * @param array (list array, message string, link string, uid int, access_token string)
  * Sends a new direct message to many users from the authenticating user.
  * @param  string $params['oauth_token'] The token to use.
  * @param  string $params['oauth_token_secret'] The token secret to use.
  * @param  array $param['list'] An array of user IDs, up to 100 are allowed in a single request.
  * @param  string message The text of your direct message.
  * @param  string $param['link'] The link to add to your messge
  */
 public function sendInvites($params = array())
 {
     if (empty($params['message'])) {
         throw new Exception('Specify message.');
     }
     if (empty($params['list'])) {
         throw new Exception('Specify user ids.');
     }
     if (empty($params['link'])) {
         throw new Exception('Specify link.');
     }
     try {
         $user_id = $params['user_id'];
         $uid = $params['uid'];
         //get max invite per day
         $max_invite = 250;
         $service = 'twitter';
         $clientConfig = YNSOCIALBRIDGE_BOL_ApisettingService::getInstance()->getConfig($this->_plugin);
         if ($clientConfig) {
             $api_params = unserialize($clientConfig->apiParams);
             if ($api_params['max_invite_day']) {
                 $max_invite = $api_params['max_invite_day'];
             }
         }
         $count_invite = 0;
         $values = array('userId' => $user_id, 'uid' => $uid, 'service' => $service, 'date' => date('Y-m-d'));
         $total_invited = $this->getTotalInviteOfDay($values);
         $count_invite_succ = $total_invited;
         $count_invite = $total_invited;
         $count_queues = 0;
         $arr_user_queues = array();
         // send message to user ids
         foreach ($params['list'] as $key => $name) {
             if ($count_invite < $max_invite) {
                 $params['user_id'] = $key;
                 $this->sendInvite($params);
                 $count_invite_succ++;
             } else {
                 $count_queues++;
                 $arr_user_queues[$key] = $name;
             }
             $count_invite++;
         }
         //save statistics
         $values = array('userId' => $user_id, 'uid' => $uid, 'service' => $service, 'inviteOfDay' => $count_invite_succ, 'date' => date('Y-m-d'));
         $this->createOrUpdateStatistic($values);
         // Save queues
         if ($count_queues > 0) {
             $values = array('uid' => $uid, 'service' => $service, 'userId' => $user_id);
             $token = $this->getToken($values);
             if ($token) {
                 $extra_params['list'] = $arr_user_queues;
                 $extra_params['link'] = $params['link'];
                 $extra_params['message'] = $params['message'];
                 $values = array('tokenId' => $token->id, 'userId' => $user_id, 'service' => $service, 'type' => 'sendInvite', 'extraParams' => serialize($extra_params), 'lastRun' => time(), 'status' => 0);
                 $this->saveQueues($values);
             }
         }
         return true;
     } catch (Exception $e) {
         echo $e->getMessage();
         return false;
     }
 }
Exemple #11
0
 public function import()
 {
     if (!OW::getUser()->isAuthenticated()) {
         throw new AuthenticateException();
     }
     if (!OW::getUser()->isAuthorized('yncontactimporter', 'invite')) {
         $this->setTemplate(OW::getPluginManager()->getPlugin('base')->getCtrlViewDir() . 'authorization_failed.html');
         return;
     }
     $el = $this->menu->getElement('1');
     if ($el) {
         $el->setActive(true);
     }
     OW::getDocument()->setTitle(OW::getLanguage()->text('yncontactimporter', 'meta_title_invite_import'));
     OW::getDocument()->setDescription(OW::getLanguage()->text('yncontactimporter', 'meta_description_invite_import'));
     $userId = OW::getUser()->getId();
     if (isset($_REQUEST['service']) || OW::getRequest()->isPost()) {
         //add friends if the email was been used in system
         if (isset($_REQUEST['task']) && $_REQUEST['task'] == 'do_add') {
             $service = FRIENDS_BOL_Service::getInstance();
             $count_addFriends = 0;
             $aFriendIdSelected = explode(',', $_POST['friendIds']);
             foreach ($aFriendIdSelected as $key => $val) {
                 if ($val) {
                     $email = $val;
                     $user = BOL_UserService::getInstance()->findByEmail($email);
                     if ($user && $service->findFriendship($userId, $user->id) === null) {
                         $service->request($userId, $user->id);
                         $this->onRequest($user->id);
                         $count_addFriends++;
                     }
                 }
             }
             if ($count_addFriends > 0) {
                 OW::getFeedback()->info(OW::getLanguage()->text('friends', 'feedback_request_was_sent'));
             }
         }
         //end add friends
         $provider = '';
         if (isset($_REQUEST['service'])) {
             $provider = $_REQUEST['service'];
         }
         if (isset($_POST['contact']) && $_POST['contact'] != "") {
             $provider = "yahoo_google_hotmail_csv";
         }
         $importUrl = OW::getRouter()->urlForRoute('yncontactimporter-import');
         $useSocialBridge = 0;
         $contacts = null;
         $totalFriends = 0;
         $totalFriendSearch = 0;
         $contacts_add = NULL;
         $maxInvite = 10;
         $totalIvited = 0;
         $gmailContacts = "";
         $obj = null;
         if (in_array($provider, array('facebook', 'twitter', 'linkedin'))) {
             $core = new YNCONTACTIMPORTER_CLASS_Core();
             if (!$core->checkSocialBridgePlugin($provider)) {
                 OW::getFeedback()->warning(OW::getLanguage()->text('yncontactimporter', 'selected_fail'));
                 $this->redirect($importUrl);
             }
             $core = new YNSOCIALBRIDGE_CLASS_Core();
             $obj = $core->getInstance($provider);
             $tokenDto = null;
             if (empty($_SESSION['socialbridge_session'][$provider])) {
                 $values = array('service' => $provider, 'userId' => OW::getUser()->getId());
                 $tokenDto = $obj->getToken($values);
             }
             $useSocialBridge = 1;
             $clientConfig = YNSOCIALBRIDGE_BOL_ApisettingService::getInstance()->getConfig($provider);
             if ($clientConfig) {
                 $api_params = unserialize($clientConfig->apiParams);
                 if (isset($api_params['max_invite_day'])) {
                     $maxInvite = $api_params['max_invite_day'];
                 }
             }
         }
         switch ($provider) {
             case 'facebook':
                 if (!empty($_SESSION['socialbridge_session'][$provider]['access_token']) || $tokenDto) {
                     if ($tokenDto) {
                         $_SESSION['socialbridge_session'][$provider]['access_token'] = $tokenDto->accessToken;
                     }
                     $uid = $obj->getOwnerId(array('access_token' => $_SESSION['socialbridge_session']['facebook']['access_token']));
                     $permissions = $obj->hasPermission(array('uid' => $uid, 'access_token' => $_SESSION['socialbridge_session'][$provider]['access_token']));
                     if (empty($permissions[0]['publish_stream']) || empty($permissions[0]['xmpp_login'])) {
                         $this->redirect($importUrl);
                     } else {
                         $friendsInvited = YNCONTACTIMPORTER_BOL_InvitationService::getInstance()->getInvitationsByUserId(array('userId' => $userId, 'provider' => 'facebook'));
                         $arr_invited = array();
                         foreach ($friendsInvited as $invitation) {
                             $arr_invited[] = $invitation->friendId;
                         }
                         $params = $_SESSION['socialbridge_session'][$provider];
                         $params['invited'] = $arr_invited;
                         $totalFriends = $obj->getTotalFriends($params);
                         $totalFriendSearch = $totalFriends;
                         $contactPerPage = (int) OW::getConfig()->getValue('yncontactimporter', 'contact_per_page');
                         $params['limit'] = $contactPerPage;
                         $params['offset'] = 0;
                         if (isset($_REQUEST['search_page_id'])) {
                             $params['offset'] = $contactPerPage * ($_REQUEST['search_page_id'] - 1);
                         }
                         if (isset($_REQUEST['search'])) {
                             $params['search'] = $_REQUEST['search'];
                             $totalFriendSearch = $obj->getTotalFriends($params);
                         }
                         $contacts = $obj->getContacts($params);
                         //get total invited
                         $values = array('uid' => $uid, 'service' => $provider, 'date' => date('Y-m-d'));
                         $totalIvited = $obj->getTotalInviteOfDay($values);
                     }
                 } else {
                     $this->redirect($obj->getConnectUrl() . '?scope=publish_stream,xmpp_login' . '&' . http_build_query(array('callbackUrl' => $importUrl)));
                 }
                 break;
             case 'twitter':
                 if (!empty($_SESSION['socialbridge_session'][$provider]['access_token']) || $tokenDto) {
                     if ($tokenDto) {
                         $_SESSION['socialbridge_session'][$provider]['access_token'] = $tokenDto->accessToken;
                         $_SESSION['socialbridge_session'][$provider]['secret_token'] = $tokenDto->secretToken;
                         $_SESSION['socialbridge_session'][$provider]['owner_id'] = $tokenDto->uid;
                     }
                     $params = $_SESSION['socialbridge_session'][$provider];
                     $params['user_id'] = $params['owner_id'];
                     $tmp_contacts = $obj->getContacts($params);
                     foreach ($tmp_contacts as $key => $value) {
                         if (!YNCONTACTIMPORTER_BOL_InvitationService::getInstance()->checkInvitedUser($key)) {
                             $contacts[$key] = $value;
                         }
                     }
                     //get total invited
                     $values = array('uid' => $params['user_id'], 'service' => $provider, 'date' => date('Y-m-d'));
                     $totalIvited = $obj->getTotalInviteOfDay($values);
                 } else {
                     $this->redirect($obj->getConnectUrl() . '?' . http_build_query(array('callbackUrl' => $importUrl)));
                 }
                 break;
             case 'linkedin':
                 if (!empty($_SESSION['socialbridge_session'][$provider]['access_token']) || $tokenDto) {
                     if ($tokenDto) {
                         $_SESSION['socialbridge_session'][$provider]['access_token'] = $tokenDto->accessToken;
                         $_SESSION['socialbridge_session'][$provider]['secret_token'] = $tokenDto->secretToken;
                     }
                     $params = $_SESSION['socialbridge_session'][$provider];
                     $tmp_contacts = $obj->getContacts($params);
                     foreach ($tmp_contacts as $key => $value) {
                         if (!YNCONTACTIMPORTER_BOL_InvitationService::getInstance()->checkInvitedUser($key)) {
                             $contacts[$key] = $value;
                         }
                     }
                     //get total invited
                     $values = array('uid' => $obj->getOwnerId($params), 'service' => $provider, 'date' => date('Y-m-d'));
                     $totalIvited = $obj->getTotalInviteOfDay($values);
                 } else {
                     $this->redirect($obj->getConnectUrl() . '?scope=r_network,w_messages&' . http_build_query(array('callbackUrl' => $importUrl)));
                 }
                 break;
             case 'yahoo_google_hotmail_csv':
                 $aContacts = $_POST['contact'];
                 $gmailContacts = $aContacts;
                 $aContacts = urldecode($aContacts);
                 $aContacts = json_decode($aContacts);
                 foreach ($aContacts as $aContact) {
                     //check email
                     if ($user = BOL_UserService::getInstance()->findByEmail($aContact->email)) {
                         $service = FRIENDS_BOL_Service::getInstance();
                         if ($service->findFriendship($userId, $user->id) === null && $userId != $user->id) {
                             $contacts_add[$aContact->email] = $aContact->name;
                         }
                     } else {
                         if (!YNCONTACTIMPORTER_BOL_InvitationService::getInstance()->checkInvitedUser($aContact->email)) {
                             $contacts[$aContact->email] = $aContact->name;
                         }
                     }
                 }
                 break;
         }
         if (count($contacts) == 0) {
             OW::getFeedback()->warning(OW::getLanguage()->text('yncontactimporter', 'no_contact'));
         }
         $this->assign('showContacts', true);
         //check invite or add friends
         $component = new YNCONTACTIMPORTER_CMP_InviteFriends(array('contacts' => $contacts, 'totalFriends' => $totalFriends, 'totalFriendSearch' => $totalFriendSearch, 'contacts_add' => $contacts_add, 'provider' => $provider, 'service' => $_REQUEST['service'], 'useSocialBridge' => $useSocialBridge, 'maxInvite' => $maxInvite, 'totalInvited' => $totalIvited, 'gmailContacts' => $gmailContacts));
         $this->addComponent('contactImports', $component);
     } else {
         $this->assign('showContacts', false);
         $providers = YNCONTACTIMPORTER_BOL_ProviderService::getInstance()->getAllProviders(array('enable' => 1));
         $arr_providers = array();
         foreach ($providers as $provider) {
             if (in_array($provider->name, array('facebook', 'twitter', 'linkedin'))) {
                 $core = new YNCONTACTIMPORTER_CLASS_Core();
                 if (!$core->checkSocialBridgePlugin($provider->name)) {
                     continue;
                 }
             }
             $item = array();
             $item['title'] = $provider->title;
             $item['name'] = $provider->name;
             $item['id'] = $provider->id;
             $item['logo'] = OW::getPluginManager()->getPlugin('yncontactimporter')->getStaticUrl() . "img/" . $provider->name . ".png";
             $arr_providers[] = $item;
         }
         $this->assign('providers', $arr_providers);
         $this->assign("uploadCSVTitle", OW::getLanguage()->text('yncontactimporter', 'upload_csv_file'));
         $this->assign("customInviteTitle", OW::getLanguage()->text('yncontactimporter', 'custom_invite'));
         $this->assign("customInviteDescription", OW::getLanguage()->text('yncontactimporter', 'custom_invite_description'));
         $link = OW::getRequest()->buildUrlQueryString(OW::getRouter()->urlForRoute('yncontactimporter-user-join'), array('refId' => $userId));
         $this->assign('urlInvite', $link);
         $this->assign('authorization', OW::getLanguage()->text('yncontactimporter', 'authorization'));
         $this->assign('import_your_contacts', OW::getLanguage()->text('yncontactimporter', 'import_your_contacts'));
         // get top inviter
         $this->assign('topInviters', YNCONTACTIMPORTER_BOL_InvitationService::getInstance()->getTopInviters());
         // get statistic
         $this->assign('statistics', YNCONTACTIMPORTER_BOL_InvitationService::getInstance()->getStatistics());
         unset($_SESSION['ynfriends_checked']);
     }
 }
Exemple #12
0
 /**
  * Send invites
  *
  * @param array (list array, message string, link string, uid int, access_token string)
  * @return bool
  */
 public function sendInvites($arr = array())
 {
     if ($this->_objPlugin) {
         try {
             $mailtemp = $arr['message'] . $arr['link'];
             $user_id = $arr['user_id'];
             $uid = $arr['uid'];
             $this->initConnect($arr);
             //get max invite per day
             $max_invite = 10;
             $clientConfig = YNSOCIALBRIDGE_BOL_ApisettingService::getInstance()->getConfig($this->_plugin);
             if ($clientConfig) {
                 $api_params = unserialize($clientConfig->apiParams);
                 if ($api_params['max_invite_day']) {
                     $max_invite = $api_params['max_invite_day'];
                 }
             }
             $count_invite = 0;
             $values = array('userId' => $user_id, 'uid' => $uid, 'service' => $this->_plugin, 'date' => date('Y-m-d'));
             $total_invited = $this->getTotalInviteOfDay($values);
             $count_invite_succ = $total_invited;
             $count_invite = $total_invited;
             $count_queues = 0;
             $arr_user_queues = array();
             $members = array();
             foreach ($arr['list'] as $key => $name) {
                 if ($count_invite < $max_invite) {
                     $members[] = $key;
                 } else {
                     $count_queues++;
                     $arr_user_queues[$key] = $name;
                 }
                 $count_invite++;
             }
             if (count($members) > 0) {
                 $response = $this->_objPlugin->message($members, BOL_UserService::getInstance()->getDisplayName($user_id), htmlspecialchars($mailtemp), true);
                 if ($response['success'] === TRUE) {
                     $count_invite_succ = $count_invite_succ + count($members);
                 }
             }
             //save statistics
             $values = array('userId' => $user_id, 'uid' => $uid, 'service' => $this->_plugin, 'inviteOfDay' => $count_invite_succ, 'date' => date('Y-m-d'));
             $this->createOrUpdateStatistic($values);
             // Save queues
             if ($count_queues > 0) {
                 $values = array('uid' => $uid, 'service' => $this->_plugin, 'userId' => $user_id);
                 $token = $this->getToken($values);
                 if ($token) {
                     $extra_params['list'] = $arr_user_queues;
                     $extra_params['link'] = $arr['link'];
                     $extra_params['message'] = $arr['message'];
                     $values = array('tokenId' => $token->id, 'userId' => $user_id, 'service' => $this->_plugin, 'type' => 'sendInvite', 'extraParams' => serialize($extra_params), 'lastRun' => time(), 'status' => 0);
                     $this->saveQueues($values);
                 }
             }
             return true;
         } catch (Exception $e) {
             echo "Error sending message:\n\nRESPONSE:\n\n" . print_r($e->getMessage(), TRUE) . "\n\nLINKEDIN OBJ:\n\n";
             return false;
         }
     }
 }
Exemple #13
0
 public function __construct($pluginKey, $entityType, $entityId)
 {
     // remove newfeeds cookie if has
     setcookie('ynsocialpublisher_feed_data_' . $entityId, '', -1, '/');
     parent::__construct();
     $userId = OW::getUser()->getId();
     $language = OW::getLanguage();
     $service = YNSOCIALPUBLISHER_BOL_Service::getInstance();
     $core = YNSOCIALPUBLISHER_CLASS_Core::getInstance();
     // user setting
     $userSetting = $service->getUsersetting($userId, $pluginKey);
     $this->assign('userSetting', $userSetting);
     // avatar
     $avatar = BOL_AvatarService::getInstance()->getAvatarUrl($userId);
     if (empty($avatar)) {
         $avatar = BOL_AvatarService::getInstance()->getDefaultAvatarUrl();
     }
     $this->assign('avatar', $avatar);
     // default status
     $defaultStatus = $core->getDefaultStatus($pluginKey, $entityType, $entityId);
     $this->assign('defaultStatus', $defaultStatus);
     // entity url
     $url = $core->getUrl($pluginKey, $entityType, $entityId);
     $this->assign('url', $url);
     // title
     $title = $core->getTitle($pluginKey, $entityType, $entityId);
     $this->assign('title', $title);
     // -- connect each provider to get data
     // callbackUrl
     $callbackUrl = OW::getRouter()->urlForRoute('ynsocialbridge-connects');
     $coreBridge = new YNSOCIALBRIDGE_CLASS_Core();
     $arrObjServices = array();
     foreach (array('facebook', 'twitter', 'linkedin') as $serviceName) {
         $profile = null;
         $connect_url = "";
         $access_token = "";
         $scope = '';
         $objService = array();
         //check enable API
         $clientConfig = YNSOCIALBRIDGE_BOL_ApisettingService::getInstance()->getConfig($serviceName);
         if ($clientConfig) {
             $obj = $coreBridge->getInstance($serviceName);
             $values = array('service' => $serviceName, 'userId' => OW::getUser()->getId());
             //$tokenDto = $obj -> getToken($values);
             //print_r($_SESSION['socialbridge_session'][$serviceName]);die;
             $disconnect_url = OW::getRouter()->urlForRoute('ynsocialbridge-disconnect') . "?service=" . $serviceName;
             if (!empty($_SESSION['socialbridge_session'][$serviceName]['access_token'])) {
                 if ($serviceName == 'facebook') {
                     $access_token = $_SESSION['socialbridge_session'][$serviceName]['access_token'];
                     //check permission
                     $me = $obj->getOwnerInfo(array('access_token' => $access_token));
                     $uid = $me['id'];
                     $permissions = $obj->hasPermission(array('uid' => $uid, 'access_token' => $access_token));
                     if ($permissions) {
                         if (empty($permissions[0]['publish_stream']) || empty($permissions[0]['status_update'])) {
                             $scope = 'publish_stream,status_update';
                             //$scope = "email,user_about_me,user_birthday,user_hometown,user_interests,user_location,user_photos,user_website,publish_stream,status_update";
                         } else {
                             try {
                                 $profile = $obj->getOwnerInfo($_SESSION['socialbridge_session'][$serviceName]);
                             } catch (Exception $e) {
                                 $profile = null;
                             }
                         }
                     }
                 } else {
                     $profile = $obj->getOwnerInfo($_SESSION['socialbridge_session'][$serviceName]);
                 }
             } else {
                 $scope = "";
                 switch ($serviceName) {
                     case 'facebook':
                         //$scope = "email,user_about_me,user_birthday,user_hometown,user_interests,user_location,user_photos,user_website";
                         $scope = 'publish_stream,status_update';
                         break;
                     case 'twitter':
                         $scope = "";
                         break;
                     case 'linkedin':
                         $scope = "r_basicprofile,rw_nus,r_network,w_messages";
                         break;
                 }
             }
             $connect_url = $obj->getConnectUrl() . "?scope=" . $scope . "&" . http_build_query(array('callbackUrl' => $callbackUrl, 'isFromSocialPublisher' => 1, 'pluginKey' => $pluginKey, 'entityType' => $entityType, 'entityId' => $entityId));
             $objService['has_config'] = 1;
         } else {
             $objService['has_config'] = 0;
         }
         $objService['serviceName'] = $serviceName;
         $objService['connectUrl'] = $connect_url;
         $objService['disconnectUrl'] = $disconnect_url;
         $objService['profile'] = $profile;
         $objService['logo'] = OW::getPluginManager()->getPlugin('ynsocialpublisher')->getStaticUrl() . "img/" . $serviceName . ".png";
         $arrObjServices[$serviceName] = $objService;
     }
     //print_r($userSetting);
     //print_r($arrObjServices);
     $this->assign('arrObjServices', $arrObjServices);
     // create form
     $formUrl = OW::getRouter()->urlFor('YNSOCIALPUBLISHER_CTRL_Ynsocialpublisher', 'ajaxPublish');
     $form = new Form('ynsocialpubisher_share');
     $form->setAction($formUrl);
     $form->setAjax();
     // -- hidden fields
     // for plugin key
     $pluginKeyHiddenField = new HiddenField('ynsocialpublisher_pluginKey');
     $pluginKeyHiddenField->setValue($pluginKey);
     $form->addElement($pluginKeyHiddenField);
     // for entity id
     $entityIdHiddenField = new HiddenField('ynsocialpublisher_entityId');
     $entityIdHiddenField->setValue($entityId);
     $form->addElement($entityIdHiddenField);
     // for entity type
     $entityTypeHiddenField = new HiddenField('ynsocialpublisher_entityType');
     $entityTypeHiddenField->setValue($entityType);
     $form->addElement($entityTypeHiddenField);
     // Status - textarea
     $status = new Textarea('ynsocialpublisher_status');
     $status->setValue($defaultStatus);
     $form->addElement($status);
     // Options - radio buttons
     $options = new RadioField('ynsocialpublisher_options');
     $options->setRequired();
     $options->addOptions(array('0' => $language->text('ynsocialpublisher', 'ask'), '1' => $language->text('ynsocialpublisher', 'auto'), '2' => $language->text('ynsocialpublisher', 'not_ask')));
     $options->setValue($userSetting['option']);
     $form->addElement($options);
     // Providers - checkboxes
     foreach (array('facebook', 'twitter', 'linkedin') as $provider) {
         if (in_array($provider, $userSetting['adminProviders']) && $arrObjServices[$provider]['has_config']) {
             $providerField = new CheckboxField('ynsocialpublisher_' . $provider);
             $form->addElement($providerField);
         }
     }
     // add js action to form
     $form->bindJsFunction(Form::BIND_SUCCESS, 'function(data){if( data.result ){OW.info(data.message);OWActiveFloatBox.close();}else{OW.error(data.message);}}');
     // submit button
     $submit = new Submit('submit');
     $submit->setValue(OW::getLanguage()->text('ynsocialpublisher', 'submit_label'));
     $form->addElement($submit);
     $this->addForm($form);
     // assign to view
     $this->assign('formUrl', $formUrl);
 }
Exemple #14
0
 /**
  * LinkedIn action
  */
 public function linkedin()
 {
     $servive = 'linkedin';
     //setting linkedin form
     $clientConfig = YNSOCIALBRIDGE_BOL_ApisettingService::getInstance()->getConfig($servive);
     $form = new YNSOCIALBRIDGE_CLASS_SettingsForm($clientConfig, $servive);
     if (OW::getRequest()->isPost() && $form->isValid($_POST)) {
         $data = $form->getValues();
         if (!$clientConfig) {
             $clientConfig = new YNSOCIALBRIDGE_BOL_Apisetting();
         }
         $params = array('key' => $data['key'], 'secret' => $data['secret']);
         if ($this->_contactImporterPlugin) {
             $params['max_invite_day'] = $data['max_invite_day'];
         }
         $clientConfig->apiParams = serialize($params);
         $clientConfig->apiName = $servive;
         YNSOCIALBRIDGE_BOL_ApisettingService::getInstance()->save($clientConfig);
         OW::getFeedback()->info(OW::getLanguage()->text('ynsocialbridge', $servive . '_settings_updated'));
     }
     $this->addForm($form);
 }
Exemple #15
0
 /**
  * Send invites
  *
  * @param array (list array, message string, link string, uid int, access_token string)
  * @return bool
  */
 public function sendInvites($params = array())
 {
     $list = $params['list'];
     $message = $params['message'];
     $link = $params['link'];
     $uid = $params['uid'];
     $user_id = $params['user_id'];
     if (isset($list)) {
         $api = new YNSOCIALBRIDGE_CLASS_FacebookChat();
         $options = array('uid' => $uid, 'app_id' => $this->_objPlugin->getAppId(), 'server' => 'chat.facebook.com');
         $access_token = $params['access_token'];
         $connectResult = $api->xmpp_connect($options, $access_token);
         if (!$connectResult) {
             echo 'connect failed';
         }
         $sMessage = $message . ' ' . $link;
         //get max invite per day
         $max_invite = 20;
         $clientConfig = YNSOCIALBRIDGE_BOL_ApisettingService::getInstance()->getConfig($this->_plugin);
         if ($clientConfig) {
             $api_params = unserialize($clientConfig->apiParams);
             if ($api_params['max_invite_day']) {
                 $max_invite = $api_params['max_invite_day'];
             }
         }
         $count_invite = 0;
         $values = array('userId' => $user_id, 'uid' => $uid, 'service' => $this->_plugin, 'date' => date('Y-m-d'));
         $total_invited = $this->getTotalInviteOfDay($values);
         $count_invite_succ = $total_invited;
         $count_invite = $total_invited;
         $count_queues = 0;
         $arr_user_queues = array();
         foreach ($list as $key => $user) {
             try {
                 if ($count_invite < $max_invite) {
                     $sendMessageResult = $api->xmpp_message($to = $key, $body = $sMessage);
                     if (!$sendMessageResult) {
                         $count_queues++;
                         $arr_user_queues[$key] = $user;
                     } else {
                         $count_invite_succ++;
                     }
                 } else {
                     $count_queues++;
                     $arr_user_queues[$key] = $user;
                 }
                 $count_invite++;
             } catch (Exception $e) {
                 throw $e;
             }
         }
         //save statistics
         $values = array('userId' => $user_id, 'uid' => $uid, 'service' => $this->_plugin, 'inviteOfDay' => $count_invite_succ, 'date' => date('Y-m-d'));
         $this->createOrUpdateStatistic($values);
         // Save queues
         if ($count_queues > 0) {
             $values = array('uid' => $uid, 'service' => $this->_plugin, 'userId' => $user_id);
             $token = $this->getToken($values);
             if ($token) {
                 $extra_params['list'] = $arr_user_queues;
                 $extra_params['link'] = $link;
                 $extra_params['message'] = $message;
                 $values = array('tokenId' => $token->id, 'userId' => $user_id, 'service' => $this->_plugin, 'type' => 'sendInvite', 'extraParams' => serialize($extra_params), 'lastRun' => time(), 'status' => 0);
                 $this->saveQueues($values);
             }
         }
         return true;
     }
     return false;
 }