本文整理汇总了PHP中FD::avatar方法的典型用法代码示例。如果您正苦于以下问题:PHP FD::avatar方法的具体用法?PHP FD::avatar怎么用?PHP FD::avatar使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FD
的用法示例。
在下文中一共展示了FD::avatar方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: processAvatar
private function processAvatar()
{
$db = FD::db();
$sql = $db->sql();
$query = 'select a.*';
$query .= ' from `#__comprofiler` as a';
$query .= ' where not exists ( ';
$query .= ' select b.`id` from `#__social_migrators` as b';
$query .= ' where a.`user_id` = b.`oid` and b.`element` = ' . $db->Quote('avatar') . ' and b.`component` = ' . $db->Quote($this->name);
$query .= ' )';
$query .= ' and a.`avatar` is not null';
$query .= ' and a.`avatarapproved` = 1';
$query .= ' ORDER BY a.`user_id` ASC';
$query .= ' LIMIT ' . $this->limit;
$sql->raw($query);
$db->setQuery($sql);
$cbAvatars = $db->loadObjectList();
if (count($cbAvatars) <= 0) {
return null;
}
foreach ($cbAvatars as $cbAvatar) {
if (!$cbAvatar->avatar) {
// no need to process further.
$this->log('avatar', $cbAvatar->user_id, $cbAvatar->user_id);
$this->info->setInfo('User ' . $cbAvatar->user_id . ' is using default avatar. no migration is needed.');
continue;
}
$userid = $cbAvatar->user_id;
// images/avatar/c7a88f6daec02aea3fd3bc4e.jpg
$imagePath = JPATH_ROOT . '/images/comprofiler/' . $cbAvatar->avatar;
$tmp = explode('/', $imagePath);
$filename = $tmp[count($tmp) - 1];
if (!JFile::exists($imagePath)) {
$this->log('avatar', $cbAvatar->user_id, $cbAvatar->user_id);
$this->info->setInfo('User ' . $cbAvatar->user_id . ' the avatar image file is not found from the server. Process aborted.');
continue;
}
// lets copy this file to tmp folder 1st.
$tmp = JFactory::getConfig()->get('tmp_path');
$tmpImageFile = $tmp . '/' . md5(JFactory::getDate()->toSql());
JFile::copy($imagePath, $tmpImageFile);
$image = FD::image();
$image->load($tmpImageFile);
$avatar = FD::avatar($image, $userid, 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($userid, SOCIAL_TYPE_USER, SOCIAL_ALBUM_PROFILE_PHOTOS);
// we need to update the album user_id to this current user.
$album->user_id = $userid;
$album->store();
$photo = FD::table('Photo');
$photo->uid = $userid;
$photo->type = SOCIAL_TYPE_USER;
$photo->user_id = $userid;
$photo->album_id = $album->id;
$photo->title = $filename;
$photo->caption = '';
$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();
// Push all the ordering of the photo down
$photosModel = FD::model('photos');
$photosModel->pushPhotosOrdering($album->id, $photo->id);
// Render 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();
}
// Create the avatars now, but we do not want the store function to create stream.
// so we pass in the option. we will create the stream ourown.
$options = array('addstream' => false);
$avatar->store($photo, $options);
// add photo privacy
$this->addItemPrivacy('photos.view', $photo->id, SOCIAL_TYPE_PHOTO, $cbAvatar->user_id, '0');
// add photo stream
$photo->addPhotosStream('uploadAvatar', $cbAvatar->lastupdatedate);
// log into mgirator
$this->log('avatar', $cbAvatar->user_id, $cbAvatar->user_id);
$this->info->setInfo('User avatar ' . $cbAvatar->user_id . ' is now migrated into EasySocial.');
}
//end foreach
return $this->info;
}
示例2: processAvatar
private function processAvatar()
{
$config = FD::config();
$db = FD::db();
$sql = $db->sql();
$query = 'select a.*, c.uid as `esgroupid`';
$query .= ' from `#__community_groups` as a';
$query .= ' inner join `#__social_migrators` as c on a.`id` = c.`oid` and c.`element` = ' . $db->Quote('groups') . ' and c.`component` = ' . $db->Quote('com_community');
$query .= ' where not exists ( ';
$query .= ' select b.`id` from `#__social_migrators` as b';
$query .= ' where a.`id` = b.`oid` and b.`element` = ' . $db->Quote('groupavatar') . ' and b.`component` = ' . $db->Quote($this->name);
$query .= ' )';
$query .= ' ORDER BY a.`id` ASC';
$query .= ' LIMIT ' . $this->limit;
$sql->raw($query);
$db->setQuery($sql);
$jsGroups = $db->loadObjectList();
if (count($jsGroups) <= 0) {
return null;
}
foreach ($jsGroups as $jsGroup) {
if (!$jsGroup->avatar) {
// no need to process further.
$this->log('groupavatar', $jsGroup->id, $jsGroup->id);
$this->info->setInfo('Group ' . $jsGroup->id . ' is using default avatar. no migration is needed.');
continue;
}
$imagePath = JPATH_ROOT . '/' . $jsGroup->avatar;
$tmp = explode('/', $imagePath);
$filename = $tmp[count($tmp) - 1];
if (!JFile::exists($imagePath)) {
$this->log('groupavatar', $jsGroup->id, $jsGroup->id);
$this->info->setInfo('Group ' . $jsGroup->id . ' the avatar image file is not found from the server. Process aborted.');
continue;
}
// lets copy this file to tmp folder 1st.
$tmp = JFactory::getConfig()->get('tmp_path');
$tmpImageFile = $tmp . '/' . md5(JFactory::getDate()->toSql());
JFile::copy($imagePath, $tmpImageFile);
$image = FD::image();
$image->load($tmpImageFile);
$avatar = FD::avatar($image, $jsGroup->esgroupid, SOCIAL_TYPE_GROUP);
// Check if there's a profile photos album that already exists.
$albumModel = FD::model('Albums');
// Retrieve the group's default album
$album = $albumModel->getDefaultAlbum($jsGroup->esgroupid, SOCIAL_TYPE_GROUP, SOCIAL_ALBUM_PROFILE_PHOTOS);
$album->user_id = $jsGroup->ownerid;
$album->store();
$photo = FD::table('Photo');
$photo->uid = $jsGroup->esgroupid;
$photo->user_id = $jsGroup->ownerid;
$photo->type = SOCIAL_TYPE_GROUP;
$photo->album_id = $album->id;
$photo->title = $filename;
$photo->caption = '';
$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();
// Push all the ordering of the photo down
$photosModel = FD::model('photos');
$photosModel->pushPhotosOrdering($album->id, $photo->id);
// Render 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();
}
// Create the avatars now, but we do not want the store function to create stream.
// so we pass in the option. we will create the stream our own.
$options = array('addstream' => false);
$avatar->store($photo, $options);
// @Add stream item when a new event cover is uploaded
// get the cover update date.
$uploadDate = $this->getMediaUploadDate('groups.avatar.upload', $jsGroup->id);
if (!$uploadDate) {
// if empty, then lets just use event creation date.
$uploadDate = $jsGroup->created;
}
$photo->addPhotosStream('uploadAvatar', $uploadDate);
// log into mgirator
$this->log('groupavatar', $jsGroup->id, $photo->id);
$this->info->setInfo('Group avatar ' . $jsGroup->id . ' is now migrated into EasySocial.');
}
return $this->info;
}
示例3: createAvatar
/**
* Allows caller to set profile photo based on the photo that they have.
*
* @since 1.0
* @access public
* @return
*/
public function createAvatar()
{
// Check for request forgeries
FD::checkToken();
// Only registered users should be allowed to upload photos
FD::requireLogin();
// Get the current view
$view = $this->getCurrentView();
// Get the photo id
$id = JRequest::getInt('id');
// Try to load the photo.
$photo = FD::table('Photo');
$photo->load($id);
// Try to load the photo with the provided id.
if (!$id || !$photo->id) {
$view->setMessage(JText::_('COM_EASYSOCIAL_PHOTOS_INVALID_ID_PROVIDED'), SOCIAL_MSG_ERROR);
return $view->call(__FUNCTION__);
}
// Get the photos lib
$lib = FD::photo($photo->uid, $photo->type, $photo);
if (!$lib->canUseAvatar()) {
$view->setMessage(JText::_('COM_EASYSOCIAL_PHOTOS_NO_PERMISSION_TO_USE_PHOTO_AS_AVATAR'), SOCIAL_MSG_ERROR);
return $view->call(__FUNCTION__);
}
// Get the image object for the photo
// Use "original" not "stock" because it might be rotated before this.
$image = $photo->getImageObject('stock');
if ($image === false) {
$image = $photo->getImageObject('original');
}
// Need to rotate as necessary here because we're loading up using the stock photo and the stock photo
// is as is when the user initially uploaded.
$image->rotate($photo->getAngle());
$tmp = JFactory::getConfig()->get('tmp_path');
$tmpPath = $tmp . '/' . md5($photo->id) . $image->getExtension();
$image->save($tmpPath);
unset($image);
$image = FD::image();
$image->load($tmpPath);
// Get the current user.
$my = FD::user();
// Load up the avatar library
$avatar = FD::avatar($image, $photo->uid, $photo->type);
// Crop the image to follow the avatar format. Get the dimensions from the request.
$width = JRequest::getVar('width');
$height = JRequest::getVar('height');
$top = JRequest::getVar('top');
$left = JRequest::getVar('left');
// We need to get the temporary path so that we can delete it later once everything is done.
$avatar->crop($top, $left, $width, $height);
// Create the avatars now
$avatar->store($photo);
// Delete the temporary file.
JFile::delete($tmpPath);
return $view->call(__FUNCTION__, $photo);
}
示例4: upload
/**
* Responsible to store the uploaded images.
*
* @since 1.0
* @access public
* @param null
*
* @author Mark Lee <mark@stackideas.com>
*/
public function upload($files)
{
// Get config object.
$config = FD::config();
// Do not proceed if image doesn't exist.
if (empty($files) || !isset($files['file'])) {
$this->setError(JText::_('COM_EASYSOCIAL_PROFILES_DEFAULT_AVATARS_FILE_UNAVAILABLE'));
return false;
}
// Get the single file input since the $files is an array.
$file = $files['file'];
// Get the default avatars storage location.
$avatarsPath = JPATH_ROOT . '/' . FD::cleanPath($config->get('avatars.storage.container'));
// Test if the avatars path folder exists. If it doesn't we need to create it.
if (!FD::makeFolder($avatarsPath)) {
$this->setError(JText::_('Errors when creating default container for avatar'));
return false;
}
// Get the defaults avatar path.
$defaultsPath = $avatarsPath . '/' . FD::cleanPath($config->get('avatars.storage.default'));
// Ensure that the defaults path exist
if (!FD::makeFolder($defaultsPath)) {
$this->setError(JText::_('Errors when creating default path for avatar'));
return false;
}
// Get the default avatars storage location for this type.
$typePath = $config->get('avatars.storage.defaults.' . $this->type);
$storagePath = $defaultsPath . '/' . FD::cleanPath($typePath);
// Ensure storage path exists.
if (!FD::makeFolder($storagePath)) {
FD::logError(__FILE__, __LINE__, 'DEFAULT_AVATARS: Unable to create the path ' . $storagePath);
$this->setError(JText::_('Errors when creating default path for avatar'));
return false;
}
// Get the profile id and construct the final path.
$idPath = FD::cleanPath($this->uid);
$storagePath = $storagePath . '/' . $idPath;
// Ensure storage path exists.
if (!FD::makeFolder($storagePath)) {
$this->setError(JText::_('Errors when creating default path for avatar'));
return false;
}
// Get the image library to perform some checks.
$image = FD::get('Image');
$image->load($file['tmp_name']);
// Test if the image is really a valid image.
if (!$image->isValid()) {
FD::logError(__FILE__, __LINE__, 'DEFAULT_AVATARS: Image uploaded ' . $file['name'] . ' is invalid');
$this->setError(JText::_('COM_EASYSOCIAL_PROFILES_DEFAULT_AVATARS_FILE_NOT_IMAGE'));
return false;
}
// Process avatar storage.
$avatar = FD::avatar($image, $this->uid, $this->type);
// Let's create the avatar.
$sizes = $avatar->create($storagePath);
// Assign the values back.
foreach ($sizes as $size => $url) {
$this->{$size} = $url;
}
return true;
}