Esempio n. 1
0
 /**
  * Insert feeds
  *
  * @param array(activities, viewer, timestamp) -- not working on oAuth2.0
  * @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 = $viewer->getIdentity();
     $uid = $params['uid'];
     $activities = $params['activities'];
     foreach ($activities as $activity) {
         if ($activity['update-content']->{'person'}->{'first-name'} != 'private') {
             $table = new Socialstream_Model_DbTable_Feeds();
             $db = $table->getAdapter();
             $db->beginTransaction();
             try {
                 $translate = Zend_Registry::get('Zend_Translate');
                 $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':
                         $type = $translate->translate('connection');
                         //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 . $translate->translate(" has a new connection.");
                         $type = "<a href = '" . $friend_href . "' target = '_blank'>" . $type . "</a>";
                         break;
                     case 'PROF':
                         $type = $translate->translate('profile');
                         if ($activity['updated-fields']->{'update-field'}->{'name'} == 'person/skills') {
                             $skills = (array) $person['skills'];
                             if ($skills) {
                                 $description = "</br>" . $translate->translate("Skills") . " - ";
                                 $count = 0;
                                 foreach ($skills['skill'] as $skill) {
                                     $count++;
                                     $description .= $skill->{'skill'}->{'name'};
                                     if ($count < $skills['@attributes']['count']) {
                                         $description .= ', ';
                                     }
                                 }
                             }
                             $friend_description = $href_friend . $translate->translate(" has an updated profile.");
                             $friend_description .= $description;
                         }
                         $type = "<a href = '" . $friend_href . "' target = '_blank'>" . $type . "</a>";
                         break;
                     case 'JGRP':
                         $type = $translate->translate('group');
                         $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 . $translate->translate(" joined a group:");
                         $type = "<a href = '" . $arr_info['href'] . "' target = '_blank'>" . $type . "</a>";
                         break;
                     case 'SHAR':
                         $type = $translate->translate('share');
                         $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);
                         $type = "<a href = '" . (string) @$share['content']->{'eyebrow-url'} . "' target = '_blank'>" . $type . "</a>";
                         break;
                     case 'STAT':
                         $type = $translate->translate('status');
                         $regex = '@((https?://)?([-\\w]+\\.[-\\w\\.]+)+\\w(:\\d+)?(/([-\\w/_\\.]*(\\?\\S+)?)?)*)@';
                         $friend_description = preg_replace($regex, '<a href="$1">$1</a>', $friend_description);
                         $type = "<a href = '" . $friend_href . "' target = '_blank'>" . $type . "</a>";
                         break;
                     case 'PICU':
                         $type = $translate->translate('photo');
                         if ($person['id'] != 'private') {
                             $friend_description = $href_friend . $translate->translate(" has a new profile picture.");
                         }
                         $type = "<a href = '" . $friend_href . "' target = '_blank'>" . $type . "</a>";
                         break;
                     case 'PRFX':
                         $type = $translate->translate('profile');
                         $friend_description = $href_friend . $translate->translate(" has updated their extended profile data.");
                         $type = "<a href = '" . $friend_href . "' target = '_blank'>" . $type . "</a>";
                         break;
                     default:
                         $type = $translate->translate('feed');
                         $type = "<a href = '" . (string) @$person['site-standard-profile-request']->{'url'} . "' target = '_blank'>" . $type . "</a>";
                         break;
                 }
                 $values = array_merge(array('provider' => 'linkedin', 'user_id' => $user_id, 'uid' => $uid, 'timestamp' => (string) $activity['timestamp'], 'update_key' => (string) $activity['update-key'], 'update_type' => $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' => $friend_description));
                 //save feed
                 $feed = $table->createRow();
                 $feed->setFromArray($values);
                 $feed->save();
                 // Auth
                 $auth = Engine_Api::_()->authorization()->context;
                 $roles = array('owner', 'owner_member', 'everyone');
                 $settingTable = Engine_Api::_()->getDbTable('settings', 'socialstream');
                 $stream_settings = $settingTable->checkExists($viewer->getIdentity(), 'linkedin');
                 $auth_view = Engine_Api::_()->getApi('settings', 'core')->getSetting('default_li_view', 'everyone');
                 if ($stream_settings) {
                     $auth_view = $stream_settings->view_privacy;
                 }
                 $viewMax = array_search($auth_view, $roles);
                 foreach ($roles as $i => $role) {
                     $auth->setAllowed($feed, $role, 'view', $i <= $viewMax);
                     $auth->setAllowed($feed, $role, 'comment', $i <= $viewMax);
                 }
                 //Add activity
                 $this->addActivity($feed, $viewer);
                 $db->commit();
             } catch (Exception $e) {
                 $db->rollBack();
                 throw $e;
             }
         }
     }
 }
Esempio n. 2
0
 /**
  * Insert feeds
  *
  * @param array(activities, viewer, timestamp)
  * @return bool
  */
 public function insertFeeds($params = array())
 {
     $this->_objPlugin->setAccessToken($params['access_token']);
     $viewer = $params['viewer'];
     $user_id = $viewer->getIdentity();
     $uid = $params['uid'];
     $activities = $params['activities'];
     foreach ($activities as $activity) {
         $table = new Socialstream_Model_DbTable_Feeds();
         $db = $table->getAdapter();
         $db->beginTransaction();
         try {
             $obj = Engine_Api::_()->socialbridge()->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'];
             $translate = Zend_Registry::get('Zend_Translate');
             $type = $translate->translate($activity['type']);
             $type = "<a href = '" . @$activity['actions'][0]['link'] . "' target = '_blank'>" . $type . "</a>";
             if (!isset($attachment['description']) || $attachment['description'] == "") {
                 if (isset($attachment['caption']) && $attachment['caption'] != "") {
                     $attachment['description'] = $attachment['caption'];
                 }
             }
             $description = "";
             if (isset($activity['message']) && $activity['message'] != "") {
                 $description = $activity['message'];
             }
             $regex = '@((https?://)?([-\\w]+\\.[-\\w\\.]+)+\\w(:\\d+)?(/([-\\w/_\\.]*(\\?\\S+)?)?)*)@';
             $description = preg_replace($regex, '<a href="$1">$1</a>', $description);
             if (isset($activity['place'])) {
                 $description = @$activity['description'];
                 $description = preg_replace($regex, '<a href="$1">$1</a>', $description);
                 $place = $activity['place'];
                 $place_link = "<a href = 'http://www.facebook.com/" . $place['id'] . "' target='_blank'>" . $place['name'] . "</a>";
                 $description .= ' - ' . $translate->translate('at') . " " . $place_link;
             }
             $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' => $description, 'privacy' => Zend_Json::encode($activity['privacy'])));
             // save feed
             $feed = $table->createRow();
             $feed->setFromArray($values);
             $feed->save();
             // Auth
             $auth = Engine_Api::_()->authorization()->context;
             $roles = array('owner', 'owner_member', 'everyone');
             $settingTable = Engine_Api::_()->getDbTable('settings', 'socialstream');
             $stream_settings = $settingTable->checkExists($viewer->getIdentity(), 'facebook');
             $auth_view = Engine_Api::_()->getApi('settings', 'core')->getSetting('default_fb_view', 'everyone');
             if ($stream_settings) {
                 $auth_view = $stream_settings->view_privacy;
             }
             $viewMax = array_search($auth_view, $roles);
             foreach ($roles as $i => $role) {
                 $auth->setAllowed($feed, $role, 'view', $i <= $viewMax);
                 $auth->setAllowed($feed, $role, 'comment', $i <= $viewMax);
             }
             //Add activity
             $this->addActivity($feed, $viewer);
             $db->commit();
         } catch (Exception $e) {
             $db->rollBack();
             throw $e;
         }
     }
 }
Esempio n. 3
0
 /**
  * Insert feeds
  *
  * @param array(activities, viewer, timestamp)
  * @return bool
  */
 public function insertFeeds($params = array())
 {
     $this->authorize($params['access_token'], $params['secret_token']);
     $viewer = $params['viewer'];
     $user_id = $viewer->getIdentity();
     $uid = $params['uid'];
     $activities = $params['activities'];
     foreach ($activities as $activity) {
         $table = new Socialstream_Model_DbTable_Feeds();
         $db = $table->getAdapter();
         $db->beginTransaction();
         try {
             $translate = Zend_Registry::get('Zend_Translate');
             $type = $translate->translate('status');
             $type = "<a href = '" . "https://twitter.com/" . $activity['user']['screen_name'] . "/status/" . $activity['id'] . "' target = '_blank'>" . $type . "</a>";
             //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);
             $friend_description = preg_replace("/@(\\w+)/", '<a href="http://www.twitter.com/$1" target="_blank">@$1</a>', $friend_description);
             $friend_description = preg_replace("/\\#(\\w+)/", '<a href="http://search.twitter.com/search?q=$1" target="_blank">#$1</a>', $friend_description);
             $values = array_merge(array('provider' => 'twitter', 'user_id' => $user_id, 'uid' => $uid, 'timestamp' => strtotime($activity['created_at']), 'update_key' => $activity['id'], 'update_type' => $type, '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' => $friend_description));
             $feed = $table->createRow();
             $feed->setFromArray($values);
             $feed->save();
             // Auth
             $auth = Engine_Api::_()->authorization()->context;
             $roles = array('owner', 'owner_member', 'everyone');
             $settingTable = Engine_Api::_()->getDbTable('settings', 'socialstream');
             $stream_settings = $settingTable->checkExists($viewer->getIdentity(), 'twitter');
             $auth_view = Engine_Api::_()->getApi('settings', 'core')->getSetting('default_tw_view', 'everyone');
             if ($stream_settings) {
                 $auth_view = $stream_settings->view_privacy;
             }
             $viewMax = array_search($auth_view, $roles);
             foreach ($roles as $i => $role) {
                 $auth->setAllowed($feed, $role, 'view', $i <= $viewMax);
                 $auth->setAllowed($feed, $role, 'comment', $i <= $viewMax);
             }
             //Add activity
             $this->addActivity($feed, $viewer);
             $db->commit();
         } catch (Exception $e) {
             $db->rollBack();
             throw $e;
         }
     }
 }