/** * 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) { $cover = isset($data['cover']) ? $data['cover'] : ''; // If cover is not provided, skip this. if (!$cover) { return; } // Get the cover URL $coverUrl = $cover->url; // Get the session object. $uid = SocialFieldsUserCoverHelper::genUniqueId($this->inputName); // Get the user object. $user = FD::user(); // Store the cover internally first. $tmpPath = SOCIAL_TMP . '/' . $uid . '_cover'; $tmpFile = $tmpPath . '/' . $uid; // Now we need to get the image data. $connector = FD::connector(); $connector->addUrl($coverUrl); $connector->connect(); $contents = $connector->getResult($coverUrl); jimport('joomla.filesystem.file'); if (!JFile::write($tmpFile, $contents)) { FD::logError(__FILE__, __LINE__, 'AVATAR: Unable to store oauth cover to tmp folder, ' . $tmpPath); return; } // Ensure that the image is valid. if (!SocialFieldsUserCoverHelper::isValid($tmpFile)) { FD::logError(__FILE__, __LINE__, 'AVATAR: Invalid image provided for cover ' . $tmpFile); return; } // Create the default album for this cover. $album = SocialFieldsUserCoverHelper::getDefaultAlbum($user->id); // Once the album is created, create the photo object. $photo = SocialFieldsUserCoverHelper::createPhotoObject($user->id, SOCIAL_TYPE_USER, $album->id, $data['oauth_id'], true); // Set the new album with the photo as the cover. $album->cover_id = $photo->id; $album->store(); // Generates a unique name for this image. $name = md5($data['oauth_id'] . $this->inputName . FD::date()->toMySQL()); // Load our own image library $image = FD::image(); // Load up the file. $image->load($tmpFile, $name); // Load up photos library $photos = FD::get('Photos', $image); $storage = $photos->getStoragePath($album->id, $photo->id); // Create avatars $sizes = $photos->create($storage); foreach ($sizes as $size => $path) { // Now we will need to store the meta for the photo. $meta = SocialFieldsUserCoverHelper::createPhotoMeta($photo, $size, $path); } // Once all is done, we just need to update the cover table so the user // will start using this cover now. $coverTable = FD::table('Cover'); $state = $coverTable->load(array('uid' => $user->id, 'type' => SOCIAL_TYPE_USER)); // User does not have a cover. if (!$state) { $coverTable->uid = $user->id; $coverTable->type = SOCIAL_TYPE_USER; $coverTable->y = $cover->offset_y; } // Set the cover to pull from photo $coverTable->setPhotoAsCover($photo->id); // Save the cover. $coverTable->store(); }