/** * Returns class instance * * @return YNCONTACTIMPORTER_BOL_ProviderService */ public static function getInstance() { if (!isset(self::$classInstance)) { self::$classInstance = new self(); } return self::$classInstance; }
public function __construct() { $this->setPageHeading(OW::getLanguage()->text('ynsocialbridge', 'socialbridge_management_page_heading')); $this->setPageHeadingIconClass('ow_yn_socialbridge'); //Preference menu $contentMenu = new BASE_CMP_PreferenceContentMenu(); $contentMenu->getElement('socialbridge')->setActive(true); $this->addComponent('contentMenu', $contentMenu); $core = new YNSOCIALBRIDGE_CLASS_Core(); $this->menu = $core->initMenu(); $this->addComponent('menu', $this->menu); $this->service = YNSOCIALSTREAM_BOL_SocialstreamFeedService::getInstance(); //load css $cssUrl = OW::getPluginManager()->getPlugin('ynsocialbridge')->getStaticCssUrl() . 'ynsocialbridge.css'; OW::getDocument()->addStyleSheet($cssUrl); //put languages to database when chage //OW::getLanguage()->importPluginLangs(OW::getPluginManager()->getPlugin('ynsocialbridge')->getRootDir() . //'langs.zip','ynsocialbridge'); }
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; } } }
/** * Insert feeds * * @param array(activities, viewer, timestamp) * @return bool */ public function insertFeeds($params = array()) { $this->authorize($params['access_token'], $params['secret_token']); $user_id = $params['user_id']; $uid = $params['uid']; $activities = $params['activities']; //init Social stream feeds service $streamFeedService = YNSOCIALSTREAM_BOL_SocialstreamFeedService::getInstance(); $now = time(); foreach ($activities as $activity) { if (strtotime($activity['created_at']) > $params['timestamp']) { try { //parse friend_description $friend_description = (string) $activity['text']; $regex = '@((https?://)?([-\\w]+\\.[-\\w\\.]+)+\\w(:\\d+)?(/([-\\w/_\\.]*(\\?\\S+)?)?)*)@'; $friend_description = preg_replace($regex, '<a href="$1">$1</a>', $friend_description); $values = array(); $values = array_merge(array('provider' => 'twitter', 'user_id' => $user_id, 'uid' => $uid, 'timestamp' => strtotime($activity['created_at']), 'update_key' => $activity['id'], 'update_type' => 'STATUS', 'photo_url' => '', 'title' => '', 'href' => '', 'description' => '', 'friend_id' => $activity['user']['id'], 'friend_name' => $activity['user']['name'], 'friend_href' => 'https://twitter.com/' . $activity['user']['screen_name'], 'friend_description' => strip_tags($friend_description))); // save feed $streamFeedDto = $streamFeedService->parseFeedArray($values); $streamFeedService->saveFeed($streamFeedDto); //attachment todo $oembed = null; $url = null; $attachId = null; $feed = "gets <a href=\"" . $values['friend_href'] . "\" target=\"_blank\">" . $values['friend_name'] . "'s</a> feed from Twitter. <span class=\"feed_item_bodytext\">" . $values['friend_description'] . "</span>"; //$feed = $language->text('ynsocialstream', 'gets ')."<a href=\"".$values['friend_href']."\" target=\"_blank\">".$values['friend_name']."'s</a>".$language->text('ynsocialstream', ' feed from Facebook.')."<span class=\"feed_item_bodytext\">".$values['friend_description']."</span>[ph:attachment]"; //get privacy $privacy = 'everybody'; $configs = OW::getConfig()->getValues('ynsocialstream'); if (isset($configs['auth_tw_' . $user_id])) { $privacy = $configs['auth_tw_' . $user_id]; } $event = new OW_Event('feed.action', array('pluginKey' => 'newsfeed', 'entityType' => 'action', 'time' => $now++, 'entityId' => $streamFeedDto->id, 'userId' => $user_id, 'privacy' => $privacy), array('string' => $feed)); OW::getEventManager()->trigger($event); } catch (Exception $e) { throw new InvalidArgumentException('Can not insert feed from Twitter in social stream feed'); exit; } } } }
/** * Insert feeds * * @param array(activities, viewer, timestamp) * @return bool */ public function insertFeeds($params = array()) { $access['oauth_token'] = $params['access_token']; $access['oauth_token_secret'] = $params['secret_token']; $this->_objPlugin->setTokenAccess($access); //$viewer = $params['viewer']; $user_id = $params['user_id']; $uid = $params['uid']; $activities = $params['activities']; //init language $language = OW::getLanguage(); //init Social stream feeds service $streamFeedService = YNSOCIALSTREAM_BOL_SocialstreamFeedService::getInstance(); $nophoto = OW::getPluginManager()->getPlugin('ynsocialstream')->getStaticUrl() . 'img/li_nopho.png'; //init time now $now = time(); foreach ($activities as $activity) { $activity = (array) $activity; if (@$activity['timestamp'] > $params['timestamp'] && $activity['update-content']->{'person'}->{'first-name'} != 'private') { //insert feed to social stream feed try { $type = $activity['update-type']; $person = (array) $activity['update-content']->{'person'}; //friend info $friend_description = @$person['current-status']; $friend_name = (string) @$person['first-name'] . ' ' . (string) @$person['last-name']; $friend_href = (string) @$person['site-standard-profile-request']->{'url'}; $href_friend = "<a href = '" . $friend_href . "' target = '_blank'>" . $friend_name . "</a>"; $arr_info = array(); //check type and get data. switch ($type) { case 'CONN': //object info $arr_info['photo_url'] = (string) $person['connections']->{'person'}->{'picture-url'}; $arr_info['title'] = (string) $person['connections']->{'person'}->{'first-name'} . ' ' . (string) $person['connections']->{'person'}->{'last-name'}; $arr_info['href'] = (string) $person['connections']->{'person'}->{'site-standard-profile-request'}->{'url'}; $arr_info['description'] = (string) $person['connections']->{'person'}->{'headline'}; //$friend_description = $href_friend.$language->text('ynsocialstream', 'has_a_new_connection.'); $friend_description = $href_friend . ' has a new connection.'; break; case 'PROF': if ($activity['updated-fields']->{'update-field'}->{'name'} == 'person/skills') { $skills = (array) $person['skills']; if ($skills) { //$description = "</br>".$language->text('ynsocialstream', 'Skills')." - "; $description = "</br>Skills - "; $count = 0; foreach ($skills['skill'] as $skill) { $count++; $description .= $skill->{'skill'}->{'name'}; if ($count < $skills['@attributes']['count']) { $description .= ', '; } } } //$friend_description = $href_friend.$language->text('ynsocialstream', 'has_an_updated_profile'); $friend_description = $href_friend . ' has an updated profile'; $friend_description .= $description; } case 'JGRP': $group = @$person['member-groups']->{'member-group'}; $group_href = (string) @$group->{'site-group-request'}->{'url'}; $result = array(); if ($group_href) { try { $client = new Zend_Http_Client($group_href, array('maxredirects' => 2, 'timeout' => 10)); // Try to mimic the requesting user's UA $client->setHeaders(array('User-Agent' => @$_SERVER['HTTP_USER_AGENT'], 'X-Powered-By' => 'Zend Framework')); $response = $client->request(); list($contentType) = explode(';', $response->getHeader('content-type')); // Handling based on content-type switch (strtolower($contentType)) { // Images case 'image/gif': case 'image/jpeg': case 'image/jpg': case 'image/tif': // Might not work // Might not work case 'image/xbm': case 'image/xpm': case 'image/png': case 'image/bmp': // Might not work $result = $this->_parseImage($group_href, $response); break; // HTML // HTML case '': case 'text/html': $result = $this->_parseHtml($group_href, $response); break; // Plain text // Plain text case 'text/plain': $result = $this->_parseText($group_href, $response); break; // Unknown // Unknown default: break; } } catch (Exception $e) { throw $e; } } $arr_info['photo_url'] = @$result['uri']; $arr_info['title'] = @$result['title']; $arr_info['href'] = $group_href; $arr_info['description'] = @$result['description']; //$friend_description = $href_friend.$language->text('ynsocialstream', 'joined_a_group'); $friend_description = $href_friend . ' joined a group'; break; case 'SHAR': $share = (array) @$person['current-share']; $arr_info['photo_url'] = (string) @$share['content']->{'submitted-image-url'}; $arr_info['title'] = (string) @$share['content']->{'title'}; $arr_info['href'] = (string) @$share['content']->{'submitted-url'}; $arr_info['description'] = (string) @$share['content']->{'description'}; $friend_description = (string) @$share['comment']; $regex = '@((https?://)?([-\\w]+\\.[-\\w\\.]+)+\\w(:\\d+)?(/([-\\w/_\\.]*(\\?\\S+)?)?)*)@'; $friend_description = preg_replace($regex, '<a href="$1">$1</a>', $friend_description); break; case 'STAT': $regex = '@((https?://)?([-\\w]+\\.[-\\w\\.]+)+\\w(:\\d+)?(/([-\\w/_\\.]*(\\?\\S+)?)?)*)@'; $friend_description = preg_replace($regex, '<a href="$1">$1</a>', $friend_description); break; case 'PICU': if ($person['id'] != 'private') { //$friend_description = $href_friend.$language->text('ynsocialstream', 'has_a_new_profile_picture'); $friend_description = $href_friend . ' has a new profile picture'; } break; case 'PRFX': //$friend_description = $href_friend.$language->text('ynsocialstream', 'has_updated_their_extended_profile_data'); $friend_description = $href_friend . ' has updated their extended profile data'; break; default: break; } $values = array(); $values = array_merge(array('provider' => 'linkedin', 'user_id' => $user_id, 'uid' => $uid, 'timestamp' => (string) $activity['timestamp'], 'update_key' => (string) $activity['update-key'], 'update_type' => (string) $activity['update-type'], 'photo_url' => $arr_info['photo_url'], 'title' => $arr_info['title'], 'href' => $arr_info['href'], 'description' => $arr_info['description'], 'friend_id' => (string) $person['id'], 'friend_name' => $friend_name, 'friend_href' => $friend_href, 'friend_description' => strip_tags($friend_description))); // save feed $streamFeedDto = $streamFeedService->parseFeedArray($values); $streamFeedService->saveFeed($streamFeedDto); //attachment todo $oembed = null; $url = null; $attachId = null; //$feed = $language->text('ynsocialstream', 'gets ')."<a href=\"".$values['friend_href']."\" target=\"_blank\">".$values['friend_name']."'s</a>".$language->text('ynsocialstream', ' feed from Linkedin.')."<span class=\"feed_item_bodytext\">".$values['friend_description']."</span>[ph:attachment]"; $feed = "gets <a href=\"" . $values['friend_href'] . "\" target=\"_blank\">" . $values['friend_name'] . "'s</a> feed from Linkedin. <span class=\"feed_item_bodytext\">" . $values['friend_description'] . "</span>[ph:attachment]"; //get privacy $privacy = 'everybody'; $configs = OW::getConfig()->getValues('ynsocialstream'); if (isset($configs['auth_li_' . $user_id])) { $privacy = $configs['auth_li_' . $user_id]; } if (strlen($values['href']) > 0) { //$values['photo_url'] = 'http://s.c.lnkd.licdn.com/scds/common/u/images/themes/katy/ghosts/person/ghost_person_65x65_v1.png'; if (strlen($values['photo_url']) == 0) { $values['photo_url'] = $nophoto; } $oembed = array('uid' => 'nfa-feed1', 'type' => 'photo', 'genId' => null, 'thumbnail_url' => $values['photo_url'], 'href' => $values['href'], 'title' => $values['title'], 'description' => $values['description']); } if ($oembed) { $event = new OW_Event('feed.action', array('pluginKey' => 'newsfeed', 'entityType' => 'action', 'time' => $now++, 'entityId' => $streamFeedDto->id, 'userId' => $user_id, 'privacy' => $privacy), array('string' => $feed, 'attachment' => array('oembed' => $oembed, 'url' => $url, 'attachId' => $attachId))); } else { $event = new OW_Event('feed.action', array('pluginKey' => 'newsfeed', 'entityType' => 'action', 'time' => $now++, 'entityId' => $streamFeedDto->id, 'userId' => $user_id, 'privacy' => $privacy), array('string' => $feed)); } OW::getEventManager()->trigger($event); } catch (Exception $e) { throw new InvalidArgumentException('Can not insert feed from Linkedin in social stream feed'); exit; } } } }
/** * Insert feeds * * @param array(activities, viewer, timestamp) * @return bool */ public function insertFeeds($params = array()) { $this->_objPlugin->setAccessToken($params['access_token']); $user_id = $params['user_id']; $uid = $params['uid']; $activities = $params['activities']; //init Social stream feeds service $streamFeedService = YNSOCIALSTREAM_BOL_SocialstreamFeedService::getInstance(); $now = time(); foreach ($activities as $activity) { if (strtotime($activity['created_time']) > $params['timestamp']) { //insert feed to social stream feed try { $core = new YNSOCIALBRIDGE_CLASS_Core(); $obj = $core->getInstance('facebook'); $actor = $obj->getUserInfo(array('uid' => $activity['from']['id'])); $attachment['name'] = @$activity['name']; $attachment['src'] = @$activity['picture']; $attachment['href'] = @$activity['link']; $attachment['description'] = @$activity['description']; $type = $activity['type']; if (!isset($attachment['description']) || $attachment['description'] == "") { if (isset($attachment['caption']) && $attachment['caption'] != "") { $attachment['description'] = $attachment['caption']; } else { $attachment['description'] = "<a href = 'http://www.facebook.com' target='_blank'>www.facebook.com</a>"; } } $description = ""; if (isset($activity['message']) && $activity['message'] != "") { $description = $activity['message']; } elseif (isset($activity['story']) && $activity['story'] != "") { $description = $activity['story']; } $regex = '@((https?://)?([-\\w]+\\.[-\\w\\.]+)+\\w(:\\d+)?(/([-\\w/_\\.]*(\\?\\S+)?)?)*)@'; $description = preg_replace($regex, '<a href="$1">$1</a>', $description); if (isset($activity['place'])) { $place = $activity['place']; $place_link = "<a href = 'http://www.facebook.com/" . $place['id'] . "' target='_blank'>" . $place['name'] . "</a>"; $description .= ' - at ' . $place_link; } $values = array(); $values = array_merge(array('provider' => 'facebook', 'user_id' => $user_id, 'uid' => $uid, 'timestamp' => strtotime($activity['created_time']), 'update_key' => $activity['id'], 'update_type' => $type, 'photo_url' => $attachment['src'], 'title' => $attachment['name'], 'href' => $attachment['href'], 'description' => $attachment['description'], 'friend_id' => $activity['from']['id'], 'friend_name' => $actor['name'], 'friend_href' => $actor['link'], 'friend_description' => strip_tags($description), 'privacy' => json_encode($activity['privacy']))); // save feed $streamFeedDto = $streamFeedService->parseFeedArray($values); $streamFeedService->saveFeed($streamFeedDto); //attachment todo $oembed = null; $url = null; $attachId = null; $feed = "gets <a href=\"" . $values['friend_href'] . "\" target=\"_blank\">" . $values['friend_name'] . "'s</a> feed from Facebook. <span class=\"feed_item_bodytext\">" . $values['friend_description'] . "</span>[ph:attachment]"; //$feed = $language->text('ynsocialstream', 'gets ')."<a href=\"".$values['friend_href']."\" target=\"_blank\">".$values['friend_name']."'s</a>".$language->text('ynsocialstream', ' feed from Facebook.')."<span class=\"feed_item_bodytext\">".$values['friend_description']."</span>[ph:attachment]"; //get privacy $privacy = 'everybody'; $configs = OW::getConfig()->getValues('ynsocialstream'); if (isset($configs['auth_fb_' . $user_id])) { $privacy = $configs['auth_fb_' . $user_id]; } if (strlen($values['photo_url']) > 0) { $oembed = array('uid' => 'nfa-feed1', 'type' => 'photo', 'genId' => null, 'thumbnail_url' => $values['photo_url'], 'href' => $values['href'], 'title' => $values['title'], 'description' => $values['description']); } if (!empty($oembed)) { $event = new OW_Event('feed.action', array('pluginKey' => 'newsfeed', 'entityType' => 'action', 'entityId' => $streamFeedDto->id, 'userId' => $user_id, 'time' => $now++, 'privacy' => $privacy), array('string' => $feed, 'attachment' => array('oembed' => $oembed, 'url' => $url, 'attachId' => $attachId))); } else { $event = new OW_Event('feed.action', array('pluginKey' => 'newsfeed', 'entityType' => 'action', 'time' => $now++, 'entityId' => $streamFeedDto->id, 'userId' => $user_id, 'privacy' => $privacy), array('string' => $feed)); } OW::getEventManager()->trigger($event); } catch (Exception $e) { throw new InvalidArgumentException('Can not insert feed from Facebook in social stream feed'); exit; } } } }