Example #1
0
 public function __construct(BASE_CLASS_WidgetParameter $params)
 {
     parent::__construct();
     if (!OW::getUser()->isAuthorized('yncontactimporter', 'invite')) {
         $this->setVisible(false);
         return;
     }
     //load css
     $cssUrl = OW::getPluginManager()->getPlugin('yncontactimporter')->getStaticCssUrl() . 'yncontactimporter.css';
     OW::getDocument()->addStyleSheet($cssUrl);
     $limit = (int) $params->customParamList['count'];
     if (!$limit) {
         $limit = 5;
     }
     $providers = YNCONTACTIMPORTER_BOL_ProviderService::getInstance()->getAllProviders(array('limit' => $limit, '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('viewMore', OW::getRouter()->urlForRoute('yncontactimporter-import'));
     $this->assign('authorization', OW::getLanguage()->text('yncontactimporter', 'authorization'));
     $this->assign('import_your_contacts', OW::getLanguage()->text('yncontactimporter', 'import_your_contacts'));
     $this->assign("uploadCSVTitle", OW::getLanguage()->text('yncontactimporter', 'upload_csv_file'));
     //check show more
     $this->assign("showMore", 0);
     if ($limit < 9) {
         $this->assign("showMore", 1);
     }
     //get config
     $width = '30px';
     $height = '30px';
     $configs = OW::getConfig()->getValues('yncontactimporter');
     if (isset($configs['logo_width'])) {
         $width = $configs['logo_width'] . "px";
     }
     if (isset($configs['logo_height'])) {
         $height = $configs['logo_height'] . "px";
     }
     $this->assign("width", $width);
     $this->assign("height", $height);
     OW::getLanguage()->importPluginLangs(OW::getPluginManager()->getPlugin('yncontactimporter')->getRootDir() . 'langs.zip', 'yncontactimporter');
 }
Example #2
0
 /**
  * provider action
  */
 public function provider()
 {
     $el = $this->_menu->getElement('management_providers');
     if ($el) {
         $el->setActive(true);
     }
     $providers = YNCONTACTIMPORTER_BOL_ProviderService::getInstance()->getAllProviders();
     foreach ($providers as $provider) {
         if (in_array($provider->name, array('facebook', 'twitter', 'linkedin'))) {
             $core = new YNCONTACTIMPORTER_CLASS_Core();
             if (!$core->checkSocialBridgePlugin($provider->name)) {
                 continue;
             }
         }
         $arr_providers[] = array('id' => $provider->id, 'title' => $provider->title, 'logo' => OW::getPluginManager()->getPlugin('yncontactimporter')->getStaticUrl() . "img/" . $provider->name . ".png", 'enable' => $provider->enable ? OW::getLanguage()->text('yncontactimporter', 'enabled') : OW::getLanguage()->text('yncontactimporter', 'disabled'), 'order' => $provider->order);
     }
     $this->assign('providers', $arr_providers);
 }
Example #3
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']);
     }
 }