Exemplo n.º 1
0
 /**
  * Adds opengraph data for the user
  *
  * @since	1.0
  * @access	public
  * @param	string
  * @return
  */
 public function addProfile(SocialUser $user)
 {
     $config = FD::config();
     // Only proceed when opengraph is enabled
     if (!$config->get('oauth.facebook.opengraph.enabled')) {
         return;
     }
     $this->properties['type'] = 'profile';
     $this->properties['title'] = JText::sprintf('COM_EASYSOCIAL_OPENGRAPH_PROFILE_TITLE', ucfirst($user->getName()));
     $this->addImage($user->getAvatar(SOCIAL_AVATAR_MEDIUM), SOCIAL_AVATAR_MEDIUM_WIDTH, SOCIAL_AVATAR_MEDIUM_HEIGHT);
     $this->addUrl($user->getPermalink(true, true));
     return $this;
 }
Exemplo n.º 2
0
 /**
  * Resends activation emails to the user.
  *
  * @since	1.0
  * @access	public
  * @param	SocialUser			The user object.
  * @param	SocialTableProfile	The profile type.
  * @return	bool				True if success, false otherwise.
  * @author	Mark Lee <*****@*****.**>
  */
 public function resendActivation(SocialUser $user)
 {
     // Get the application data.
     $jConfig = FD::jConfig();
     $config = FD::config();
     // Push arguments to template variables so users can use these arguments
     $params = array('site' => $jConfig->getValue('sitename'), 'username' => $user->username, 'password' => $user->password_clear, 'name' => $user->getName(), 'id' => $user->id, 'avatar' => $user->getAvatar(SOCIAL_AVATAR_LARGE), 'profileLink' => $user->getPermalink(true, true), 'email' => $user->email, 'activation' => FRoute::registration(array('external' => true, 'task' => 'activate', 'controller' => 'registration', 'token' => $user->activation)), 'token' => $user->activation, 'manageAlerts' => false);
     // Get the email title.
     $title = JText::_('COM_EASYSOCIAL_REGISTRATION_ACTIVATION_REMINDER');
     // Immediately send out emails
     $mailer = FD::mailer();
     // Get the email template.
     $mailTemplate = $mailer->getTemplate();
     // Set recipient
     $mailTemplate->setRecipient($user->name, $user->email);
     // Set title
     $mailTemplate->setTitle($title);
     // Set the contents
     $mailTemplate->setTemplate('site/registration/reactivate', $params);
     // Set the priority. We need it to be sent out immediately since this is user registrations.
     $mailTemplate->setPriority(SOCIAL_MAILER_PRIORITY_IMMEDIATE);
     // Try to send out email now.
     $state = $mailer->create($mailTemplate);
     return $state;
 }
Exemplo n.º 3
0
 /**
  * Processes before the user account is created when user signs in with oauth.
  *
  * @since	1.0
  * @access	public
  * @param	string
  * @return
  */
 public function onRegisterOAuthAfterSave(&$data, &$oauthClient, SocialUser &$user)
 {
     // Let's see if avatarUrl is provided.
     if (!isset($data['avatar']) || empty($data['avatar'])) {
         return;
     }
     $avatarUrl = $data['avatar'];
     // Store the avatar internally.
     $key = md5($data['oauth_id'] . $data['username']);
     $tmpAvatarPath = SOCIAL_MEDIA . '/tmp/' . $key;
     $tmpAvatarFile = $tmpAvatarPath . '/' . $key;
     jimport('joomla.filesystem.folder');
     if (!JFolder::exists($tmpAvatarPath)) {
         $state = JFolder::create($tmpAvatarPath);
         if (!$state) {
             FD::logError(__FILE__, __LINE__, 'OAUTH: Unable to create avatar folder.');
         }
     }
     $connector = FD::get('Connector');
     $connector->addUrl($avatarUrl);
     $connector->connect();
     $contents = $connector->getResult($avatarUrl);
     jimport('joomla.filesystem.file');
     if (!JFile::write($tmpAvatarFile, $contents)) {
         dump('here');
         FD::logError(__FILE__, __LINE__, 'AVATAR: Unable to store oauth avatar to tmp folder, ' . $tmpAvatarFile);
         return;
     }
     $image = FD::image();
     $image->load($tmpAvatarFile);
     $avatar = FD::avatar($image, $user->id, SOCIAL_TYPE_USER);
     // Check if there's a profile photos album that already exists.
     $albumModel = FD::model('Albums');
     // Retrieve the user's default album
     $album = $albumModel->getDefaultAlbum($user->id, SOCIAL_TYPE_USER, SOCIAL_ALBUM_PROFILE_PHOTOS);
     $photo = FD::table('Photo');
     $photo->uid = $user->id;
     $photo->user_id = $user->id;
     $photo->type = SOCIAL_TYPE_USER;
     $photo->album_id = $album->id;
     $photo->title = $user->getName();
     $photo->caption = JText::_('COM_EASYSOCIAL_PHOTO_IMPORTED_FROM_FACEBOOK');
     $photo->ordering = 0;
     // We need to set the photo state to "SOCIAL_PHOTOS_STATE_TMP"
     $photo->state = SOCIAL_PHOTOS_STATE_TMP;
     // Try to store the photo first
     $state = $photo->store();
     if (!$state) {
         $this->setError(JText::_('PLG_FIELDS_AVATAR_ERROR_CREATING_PHOTO_OBJECT'));
         return false;
     }
     // Push all the ordering of the photo down
     $photosModel = FD::model('photos');
     $photosModel->pushPhotosOrdering($album->id, $photo->id);
     // If album doesn't have a cover, set the current photo as the cover.
     if (!$album->hasCover()) {
         $album->cover_id = $photo->id;
         // Store the album
         $album->store();
     }
     // Get the photos library
     $photoLib = FD::get('Photos', $image);
     $storage = $photoLib->getStoragePath($album->id, $photo->id);
     $paths = $photoLib->create($storage);
     // Create metadata about the photos
     foreach ($paths as $type => $fileName) {
         $meta = FD::table('PhotoMeta');
         $meta->photo_id = $photo->id;
         $meta->group = SOCIAL_PHOTOS_META_PATH;
         $meta->property = $type;
         $meta->value = $storage . '/' . $fileName;
         $meta->store();
     }
     // Synchronize Indexer
     $indexer = FD::get('Indexer');
     $template = $indexer->getTemplate();
     $template->setContent($photo->title, $photo->caption);
     // $url 	= FRoute::photos(array('layout' => 'item', 'id' => $photo->getAlias()));
     $url = $photo->getPermalink();
     $url = '/' . ltrim($url, '/');
     $url = str_replace('/administrator/', '/', $url);
     $template->setSource($photo->id, SOCIAL_INDEXER_TYPE_PHOTOS, $photo->uid, $url);
     $template->setThumbnail($photo->getSource('thumbnail'));
     $indexer->index($template);
     $options = array();
     if ($user->state == SOCIAL_USER_STATE_PENDING) {
         $options['addstream'] = false;
     }
     // Create the avatars now
     $avatar->store($photo, $options);
     // Once we are done creating the avatar, delete the temporary folder.
     $state = JFolder::delete($tmpAvatarPath);
 }
Exemplo n.º 4
0
 /**
  * Perform field saving after profile is saved
  *
  * @since	1.2
  * @access	public
  * @param	string
  * @return
  */
 public function onEditBeforeSave(&$data, SocialUser &$user)
 {
     $subscribe = isset($data[$this->inputName]) ? $data[$this->inputName] : false;
     // Get the app params
     $params = $this->field->getApp()->getParams();
     $fieldParams = $this->field->getParams();
     $defaultList = $params->get('listid');
     // Get the previous value
     $value = $this->getData();
     // If the previous value is selected and the current subscribe is faled, we assume that the user is trying to unsubscribe
     if (!$subscribe && $value && $params->get('apikey')) {
         // Try to get the first and last name of the user
         $firstName = isset($data['first_name']) ? $data['first_name'] : '';
         $lastName = isset($data['last_name']) ? $data['last_name'] : '';
         if (!$firstName) {
             $firstName = $user->getName();
         }
         // Load up mailchimp's library.
         $mailchimp = FD::mailchimp($params->get('apikey'));
         // Determine if there's a custom list id.
         $listId = $fieldParams->get('custom_list_id', $defaultList);
         $mailchimp->unsubscribe($listId, $user->email);
         // Set the data to 0
         $data[$this->inputName] = '';
     }
 }