本文整理汇总了PHP中FD::image方法的典型用法代码示例。如果您正苦于以下问题:PHP FD::image方法的具体用法?PHP FD::image怎么用?PHP FD::image使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FD
的用法示例。
在下文中一共展示了FD::image方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createCover
/**
* Some desc
*
* @since 1.0
* @access public
* @param string
* @return
*/
public function createCover($file, $inputName)
{
// Load our own image library
$image = FD::image();
// Generates a unique name for this image.
$name = $file['name'];
// Load up the file.
$image->load($file['tmp_name'], $name);
// Ensure that the image is valid.
if (!$image->isValid()) {
// @TODO: Add some logging here.
echo JText::_('PLG_FIELDS_AVATAR_VALIDATION_INVALID_IMAGE');
exit;
}
// Get the storage path
$storage = SocialFieldsUserCoverHelper::getStoragePath($inputName);
// Create a new avatar object.
$photos = FD::get('Photos', $image);
// Create avatars
$sizes = $photos->create($storage);
// We want to format the output to get the full absolute url.
$base = basename($storage);
$result = array();
foreach ($sizes as $size => $value) {
$row = new stdClass();
$row->title = $file['name'];
$row->file = $value;
$row->path = JPATH_ROOT . '/media/com_easysocial/tmp/' . $base . '/' . $value;
$row->uri = rtrim(JURI::root(), '/') . '/media/com_easysocial/tmp/' . $base . '/' . $value;
$result[$size] = $row;
}
return $result;
}
示例2: cache
/**
* Stores a given image link into the local cache
*
* @since 1.2.11
* @access public
* @param string
* @return
*/
public function cache($imageLink)
{
// Check if settings is enabled
if (!$this->config->get('links.cache.images')) {
return false;
}
// Generate a unique name for this file
$name = md5($imageLink) . '.png';
// Get the storage path
$storageFolder = FD::cleanPath($this->config->get('links.cache.location'));
$storage = JPATH_ROOT . '/' . $storageFolder . '/' . $name;
$storageURI = rtrim(JURI::root(), '/') . '/' . $storageFolder . '/' . $name;
$exists = JFile::exists($storage);
// If the file is already cached, skip this
if ($exists) {
return $storageURI;
}
// Crawl the image now.
$connector = FD::get('Connector');
$connector->addUrl($imageLink);
$connector->connect();
// Get the result and parse them.
$contents = $connector->getResult($imageLink);
// Store the file to a temporary directory first
$tmpFile = SOCIAL_TMP . '/' . $name;
JFile::write($tmpFile, $contents);
// Load the image now
$image = FD::image();
$image->load($tmpFile);
// Ensure that image is valid
if (!$image->isValid()) {
JFile::delete($tmpFile);
return false;
}
// Delete the temporary file.
JFile::delete($tmpFile);
// Unset the image now since we don't want to use asido to resize
unset($image);
// Store the file now into our cache storage.
JFile::write($storage, $contents);
return $storageURI;
}
示例3: upload
public function upload()
{
// Get the ajax library
$ajax = FD::ajax();
// Get the file
$tmp = JRequest::getVar($this->inputName, '', 'FILES');
$file = array();
foreach ($tmp as $k => $v) {
$file[$k] = $v['file'];
}
// Check if it is a valid file
if (empty($file['tmp_name'])) {
return $ajax->reject(JText::_('PLG_FIELDS_AVATAR_ERROR_INVALID_FILE'));
}
// Get user access
$access = FD::access($this->uid, SOCIAL_TYPE_CLUSTERS);
// Check if the filesize is too large
$maxFilesize = $access->get('photos.maxsize');
$maxFilesizeBytes = (int) $maxFilesize * 1048576;
if ($file['size'] > $maxFilesizeBytes) {
return $ajax->reject(JText::sprintf('COM_EASYSOCIAL_PHOTOS_UPLOAD_ERROR_FILE_SIZE_LIMIT_EXCEEDED', $maxFilesize . 'mb'));
}
// Load up the image library so we can get the appropriate extension
$image = FD::image();
$image->load($file['tmp_name']);
// Copy this to temporary location first
$tmpPath = SocialFieldsUserAvatarHelper::getStoragePath($this->inputName);
$tmpName = md5($file['name'] . $this->inputName . FD::date()->toMySQL()) . $image->getExtension();
$source = $file['tmp_name'];
$target = $tmpPath . '/' . $tmpName;
$state = JFile::copy($source, $target);
if (!$state) {
return $ajax->reject(JText::_('PLG_FIELDS_AVATAR_ERROR_UNABLE_TO_MOVE_FILE'));
}
$tmpUri = SocialFieldsUserAvatarHelper::getStorageURI($this->inputName);
$uri = $tmpUri . '/' . $tmpName;
return $ajax->resolve($file, $uri, $target);
}
示例4: processPhotos
private function processPhotos()
{
$config = FD::config();
$db = FD::db();
$sql = $db->sql();
$query = 'select c.`uid` as `esgroupid`, b.`groupid`, a.*';
$query .= ' from `#__community_photos` as a';
$query .= ' inner join `#__community_photos_albums` as b on a.`albumid` = b.`id` and b.`type` = ' . $db->Quote('group');
$query .= ' inner join `#__social_migrators` as c on b.`groupid` = 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('groupphotos') . ' and b.`component` = ' . $db->Quote($this->name);
$query .= ' )';
$query .= ' and a.`storage` = ' . $db->Quote('file');
$query .= ' ORDER BY a.`id` ASC';
$query .= ' LIMIT ' . $this->limit;
$sql->raw($query);
$db->setQuery($sql);
$jsPhotos = $db->loadObjectList();
if (count($jsPhotos) <= 0) {
return null;
}
foreach ($jsPhotos as $jsPhoto) {
if (!$jsPhoto->published) {
// photos not published. do not migrate.
// log into mgirator
$this->log('groupphotos', $jsPhoto->id, -1);
$this->info->setInfo('Photo with id \'' . $jsPhoto->id . '\' is currently in unpublished or delete state. Photo migration process aborted.');
continue;
}
$imagePath = JPATH_ROOT . '/' . $jsPhoto->original;
if (!JFile::exists($imagePath)) {
// files from originalphotos not found. let try to get it from photos folder instead.
// images/photos/84/1/e03fbd75d6e8f5fe0e542665.jpg
$imagePath = JPATH_ROOT . '/' . $jsPhoto->image;
}
if (!JFile::exists($imagePath)) {
// both image from originalphotos and photos folder not found. Lets give up.
// log into mgirator
$this->log('groupphotos', $jsPhoto->id, -1);
$this->info->setInfo('Photo with id \'' . $jsPhoto->id . '\' not found in the server. Photo migration process aborted.');
continue;
}
// lets get this photo album
$esAlbumId = $this->processJSPhotoAlbum($jsPhoto);
// lets copy this file to tmp folder 1st.
$tmp = JFactory::getConfig()->get('tmp_path');
$tmpImageFile = $tmp . '/' . md5(JFactory::getDate()->toSql());
JFile::copy($imagePath, $tmpImageFile);
$esPhoto = FD::table('Photo');
$esPhoto->uid = $jsPhoto->esgroupid;
$esPhoto->type = SOCIAL_TYPE_GROUP;
$esPhoto->user_id = $jsPhoto->creator;
$esPhoto->album_id = $esAlbumId;
// we use the filename as the title instead of caption.
$fileName = JFile::getName($imagePath);
$esPhoto->title = $fileName;
$esPhoto->caption = $jsPhoto->caption;
$esPhoto->created = $jsPhoto->created;
$esPhoto->assigned_date = $jsPhoto->created;
$esPhoto->ordering = $this->getPhotoOrdering($esAlbumId);
$esPhoto->featured = '0';
$esPhoto->state = $jsPhoto->published ? '1' : '0';
// Let's test if exif exists
$exif = FD::get('Exif');
// Load the iamge object
$image = FD::image();
$image->load($tmpImageFile);
// Detect the photo caption and title if exif is available.
if ($exif->isAvailable() && $image->hasExifSupport()) {
// Load the image
$exif->load($tmpImageFile);
$title = $exif->getTitle();
$caption = $exif->getCaption();
$createdAlias = $exif->getCreationDate();
if ($createdAlias) {
$esPhoto->assigned_date = $createdAlias;
}
if ($title) {
$esPhoto->title = $title;
}
if ($caption) {
$esPhoto->caption = $caption;
}
}
$esPhoto->store();
// Get the photos library
$photoLib = FD::get('Photos', $image);
$storage = $photoLib->getStoragePath($esAlbumId, $esPhoto->id);
$paths = $photoLib->create($storage);
// Create metadata about the photos
foreach ($paths as $type => $fileName) {
$meta = FD::table('PhotoMeta');
$meta->photo_id = $esPhoto->id;
$meta->group = SOCIAL_PHOTOS_META_PATH;
$meta->property = $type;
$meta->value = $storage . '/' . $fileName;
$meta->store();
}
// add photo stream
//.........这里部分代码省略.........
示例5: crop
/**
* Crops an image
*
* @since 1.0
* @access public
* @param string
* @return SocialImage
*/
public function crop($top = null, $left = null, $width = null, $height = null)
{
// Use the current image that was already loaded
$image = $this->image;
// Get the width and height of the photo
$imageWidth = $image->getWidth();
$imageHeight = $image->getHeight();
if (!is_null($top) && !is_null($left) && !is_null($width) && !is_null($height)) {
$actualX = $imageWidth * $left;
$actualY = $imageHeight * $top;
$actualWidth = $imageWidth * $width;
$actualHeight = $imageHeight * $height;
// Now we'll need to crop the image
$image->crop($actualX, $actualY, $actualWidth, $actualHeight);
} else {
// If caller didn't provide a crop ratio, we crop the avatar to square
// Get the correct positions
if ($imageWidth > $imageHeight) {
$x = ($imageWidth - $imageHeight) / 2;
$y = 0;
$image->crop($x, $y, $imageHeight, $imageHeight);
} else {
$x = 0;
$y = ($imageHeight - $imageWidth) / 2;
$image->crop($x, $y, $imageWidth, $imageWidth);
}
}
// We want to store the temporary image somewhere so that the image library could manipulate this file.
$tmpImagePath = md5(FD::date()->toMySQL()) . $image->getExtension();
$jConfig = FD::jconfig();
// Save the temporary cropped image
$tmpImagePath = $jConfig->getValue('tmp_path') . '/' . $tmpImagePath;
// Now, we'll want to save this temporary image.
$image->save($tmpImagePath);
// Unset the image to free up some memory
unset($image);
// Reload the image again to get the correct resource pointing to the cropped image.
$image = FD::image();
$image->load($tmpImagePath);
$this->image = $image;
return $tmpImagePath;
}
示例6: uploadPhoto
public function uploadPhoto($log_usr = 0, $type = null)
{
// Get current logged in user.
$my = FD::user($log_usr);
// Get user access
$access = FD::access($my->id, SOCIAL_TYPE_USER);
// Load up the photo library
$lib = FD::photo($log_usr, $type);
// Define uploader options
$options = array('name' => 'file', 'maxsize' => $lib->getUploadFileSizeLimit());
// Get uploaded file
$file = FD::uploader($options)->getFile();
// Load the iamge object
$image = FD::image();
$image->load($file['tmp_name'], $file['name']);
// Detect if this is a really valid image file.
if (!$image->isValid()) {
return "invalid image";
}
// Load up the album's model.
$albumsModel = FD::model('Albums');
// Create the default album if necessary
$album = $albumsModel->getDefaultAlbum($log_usr, $type, SOCIAL_ALBUM_STORY_ALBUM);
// Bind photo data
$photo = FD::table('Photo');
$photo->uid = $log_usr;
$photo->type = $type;
$photo->user_id = $my->id;
$photo->album_id = $album->id;
$photo->title = $file['name'];
$photo->caption = '';
$photo->state = 1;
$photo->ordering = 0;
// Set the creation date alias
$photo->assigned_date = FD::date()->toMySQL();
// Trigger rules that should occur before a photo is stored
$photo->beforeStore($file, $image);
// Try to store the photo.
$state = $photo->store();
// Load the photos model
$photosModel = FD::model('Photos');
// Get the storage path for this photo
$storage = FD::call('Photos', 'getStoragePath', array($album->id, $photo->id));
// Get the photos library
$photoLib = FD::get('Photos', $image);
$paths = $photoLib->create($storage);
// Create metadata about the photos
if ($paths) {
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();
// We need to store the photos dimension here
list($width, $height, $imageType, $attr) = getimagesize(JPATH_ROOT . $storage . '/' . $fileName);
// Set the photo dimensions
$meta = FD::table('PhotoMeta');
$meta->photo_id = $photo->id;
$meta->group = SOCIAL_PHOTOS_META_WIDTH;
$meta->property = $type;
$meta->value = $width;
$meta->store();
$meta = FD::table('PhotoMeta');
$meta->photo_id = $photo->id;
$meta->group = SOCIAL_PHOTOS_META_HEIGHT;
$meta->property = $type;
$meta->value = $height;
$meta->store();
}
}
// After storing the photo, trigger rules that should occur after a photo is stored
//$photo->afterStore( $file , $image );
//$sphoto = new SocialPhotos($photo_obj->id);
return $photo;
}
示例7: newInstance
public function newInstance()
{
$image = FD::image();
$image->load($this->meta->path, $this->meta->name);
return $image;
}
示例8: create
/**
* Creates the necessary images to be used as an avatar.
*
* @since 1.0
* @access public
* @param string The target location to store the avatars
* @param Array An array of excluded sizes.
* @return
*/
public function create($path, $exclusion = array(), $overrideFileName = '')
{
// Files array store a list of files
// created for this photo.
$files = array();
// Create stock image
$filename = $this->generateFilename('stock', $overrideFileName);
$file = $path . '/' . $filename;
$files['stock'] = $filename;
$this->image->copy(JPATH_ROOT . $path . '/' . $filename);
// Create original image
$filename = $this->generateFilename('original');
$file = JPATH_ROOT . $path . '/' . $filename;
$files['original'] = $filename;
$this->image->rotate(0);
// Fake an operation queue
$this->image->save($file);
// Use original image as source image
// for all other image sizes.
$sourceImage = FD::image()->load($file);
// Create the rest of the image sizes
foreach (self::$sizes as $name => $size) {
if (in_array($name, $exclusion)) {
continue;
}
// Clone an instance of the source image.
// Otherwise subsequent resizing operations
// in this loop would end up using the image
// instance that was resized by the previous loop.
$image = $sourceImage->cloneImage();
$filename = $this->generateFilename($name, $overrideFileName);
$file = JPATH_ROOT . $path . '/' . $filename;
$files[$name] = $filename;
// Resize image
$method = $size['mode'];
$image->{$method}($size['width'], $size['height']);
// Save image
$image->save($file);
// Free up memory
unset($image);
}
return $files;
}
示例9: onRegisterOAuthAfterSave
/**
* 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();
}
示例10: getImageObject
/**
* Gets the image object
*
* @since 1.0
* @access public
* @param string
* @return
*/
public function getImageObject($type)
{
$path = $this->getPath($type);
if (!JFile::exists($path)) {
return false;
}
$image = FD::image();
$image->load($path);
return $image;
}
示例11: createAvatarFromFile
/**
* Allows caller to create an avatar by posted the $_FILE data
*
* @since 1.0
* @access public
* @param string
* @return
*/
public function createAvatarFromFile()
{
// Check for request forgeries
FD::checkToken();
// Only registered users should be allowed to upload photos
FD::requireLogin();
// Get the current view
$view = $this->getCurrentView();
$config = FD::config();
// Get the unique item id
$uid = JRequest::getInt('uid');
$type = JRequest::getCmd('type');
// Get current user.
$my = FD::user();
if (!$uid && !$type) {
$view->setMessage(JText::_('COM_EASYSOCIAL_PHOTOS_INVALID_ID_PROVIDED'), SOCIAL_MSG_ERROR);
return $view->call('createAvatar');
}
// Load up the photo library
$lib = FD::photo($uid, $type);
// Set uploader options
$options = array('name' => 'avatar_file', 'maxsize' => $lib->getUploadFileSizeLimit());
// Get uploaded file
$file = FD::uploader($options)->getFile();
// If there was an error getting uploaded file, stop.
if ($file instanceof SocialException) {
$view->setMessage($file);
return $view->call('createAvatar');
}
// Load the image
$image = FD::image();
$image->load($file['tmp_name'], $file['name']);
// Check if there's a profile photos album that already exists.
$albumModel = FD::model('Albums');
// Retrieve the default album for this node.
$album = $lib->getDefaultAlbum();
$photo = FD::table('Photo');
$photo->uid = $uid;
$photo->type = $type;
$photo->user_id = $my->id;
$photo->album_id = $album->id;
$photo->title = $file['name'];
$photo->caption = '';
$photo->ordering = 0;
// Set the creation date alias
$photo->assigned_date = FD::date()->toMySQL();
// 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();
// Bind any exif data if there are any.
// Only bind exif data for jpg files (if want to add tiff, then do add it here)
if ($image->hasExifSupport()) {
$photo->mapExif($file);
}
if (!$state) {
$view->setMessage(JText::_('COM_EASYSOCIAL_PHOTOS_ERROR_CREATING_IMAGE_FILES'), SOCIAL_MSG_ERROR);
return $view->call('createAvatar');
}
// 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();
}
// Retrieve the original photo again.
$image = $photo->getImageObject('original');
return $view->call('createAvatar', $photo);
}
示例12: processAvatar
private function processAvatar()
{
$config = FD::config();
$db = FD::db();
$sql = $db->sql();
$query = 'select a.*, c.uid as `eseventid`';
$query .= ' from `#__community_events` as a';
$query .= ' inner join `#__social_migrators` as c on a.`id` = c.`oid` and c.`element` = ' . $db->Quote('events') . ' 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('eventavatar') . ' and b.`component` = ' . $db->Quote($this->name);
$query .= ' )';
$query .= ' ORDER BY a.`id` ASC';
$query .= ' LIMIT ' . $this->limit;
$sql->raw($query);
$db->setQuery($sql);
$jsEvents = $db->loadObjectList();
if (count($jsEvents) <= 0) {
return null;
}
foreach ($jsEvents as $jsEvent) {
if (!$jsEvent->avatar) {
// no need to process further.
$this->log('eventavatar', $jsEvent->id, $jsEvent->id);
$this->info->setInfo('Event ' . $jsEvent->id . ' is using default avatar. no migration is needed.');
continue;
}
$imagePath = JPATH_ROOT . '/' . $jsEvent->avatar;
$tmp = explode('/', $imagePath);
$filename = $tmp[count($tmp) - 1];
if (!JFile::exists($imagePath)) {
$this->log('eventavatar', $jsEvent->id, $jsEvent->id);
$this->info->setInfo('Event ' . $jsEvent->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, $jsEvent->eseventid, SOCIAL_TYPE_EVENT);
// Check if there's a profile photos album that already exists.
$albumModel = FD::model('Albums');
// Retrieve the group's default album
$album = $albumModel->getDefaultAlbum($jsEvent->eseventid, SOCIAL_TYPE_EVENT, SOCIAL_ALBUM_PROFILE_PHOTOS);
$album->user_id = $jsEvent->creator;
$album->store();
$photo = FD::table('Photo');
$photo->uid = $jsEvent->eseventid;
$photo->user_id = $jsEvent->creator;
$photo->type = SOCIAL_TYPE_EVENT;
$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 stream item when a new event avatar is uploaded
// get the cover update date.
$uploadDate = $this->getMediaUploadDate('events.avatar.upload', $jsEvent->id);
if (!$uploadDate) {
// if empty, then lets just use event creation date.
$uploadDate = $jsEvent->created;
}
$photo->addPhotosStream('uploadAvatar', $uploadDate);
// log into mgirator
$this->log('eventavatar', $jsEvent->id, $photo->id);
$this->info->setInfo('Event avatar ' . $jsEvent->id . ' is now migrated into EasySocial.');
}
return $this->info;
}
示例13: addPhotoAlbum
public function addPhotoAlbum($log_usr = 0, $album_id)
{
$my = FD::user();
// Load up the configuration
$config = FD::config();
// Load the album table
$album = FD::table('Album');
$album->load($album_id);
// Check if the album id provided is valid
if (!$album->id || !$album->id) {
return "album not valid";
}
// Get the uid and the type
$uid = $album->uid;
$type = $album->type;
// Load the photo library
$lib = FD::photo($uid, $type);
// Set uploader options
$options = array('name' => 'file', 'maxsize' => $lib->getUploadFileSizeLimit());
// Get uploaded file
$file = FD::uploader($options)->getFile();
// If there was an error getting uploaded file, stop.
if ($file instanceof SocialException) {
return false;
}
// Load the image object
$image = FD::image();
$image->load($file['tmp_name'], $file['name']);
// Detect if this is a really valid image file.
if (!$image->isValid()) {
return false;
}
// Bind the photo data now
$photo = FD::table('Photo');
$photo->uid = $uid;
$photo->type = $type;
$photo->user_id = $album->uid;
$photo->album_id = $album->id;
$photo->title = $file['name'];
$photo->caption = '';
$photo->ordering = 0;
$photo->state = SOCIAL_STATE_PUBLISHED;
// Set the creation date alias
$photo->assigned_date = FD::date()->toMySQL();
// Cleanup photo title.
$photo->cleanupTitle();
// Trigger rules that should occur before a photo is stored
$photo->beforeStore($file, $image);
// Try to store the photo.
$state = $photo->store();
if (!$state) {
return false;
}
// 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);
// Get the storage path for this photo
$storageContainer = FD::cleanPath($config->get('photos.storage.container'));
$storage = $photoLib->getStoragePath($album->id, $photo->id);
$paths = $photoLib->create($storage);
// We need to calculate the total size used in each photo (including all the variants)
$totalSize = 0;
// Create metadata about the photos
if ($paths) {
foreach ($paths as $type => $fileName) {
$meta = FD::table('PhotoMeta');
$meta->photo_id = $photo->id;
$meta->group = SOCIAL_PHOTOS_META_PATH;
$meta->property = $type;
// do not store the container path as this path might changed from time to time
$tmpStorage = str_replace('/' . $storageContainer . '/', '/', $storage);
$meta->value = $tmpStorage . '/' . $fileName;
$meta->store();
// We need to store the photos dimension here
list($width, $height, $imageType, $attr) = getimagesize(JPATH_ROOT . $storage . '/' . $fileName);
// Set the photo size
$totalSize += filesize(JPATH_ROOT . $storage . '/' . $fileName);
// Set the photo dimensions
$meta = FD::table('PhotoMeta');
$meta->photo_id = $photo->id;
$meta->group = SOCIAL_PHOTOS_META_WIDTH;
$meta->property = $type;
$meta->value = $width;
$meta->store();
$meta = FD::table('PhotoMeta');
$meta->photo_id = $photo->id;
$meta->group = SOCIAL_PHOTOS_META_HEIGHT;
$meta->property = $type;
$meta->value = $height;
$meta->store();
}
}
// Set the total photo size
$photo->total_size = $totalSize;
//.........这里部分代码省略.........
示例14: 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;
}
示例15: cache
/**
* Stores a given image link into the local cache
*
* @since 1.2.11
* @access public
* @param string
* @return
*/
public function cache($imageLink)
{
// Check if settings is enabled
if (!$this->config->get('links.cache.images')) {
return false;
}
// Try to load any existing cached image from the db
$linkImage = FD::table('LinkImage');
$exists = $linkImage->load(array('source_url' => $imageLink));
// If this already exists, skip this altogether
if ($exists) {
return $linkImage->internal_url;
}
// Generate a unique name for this file
$fileName = md5($imageLink) . '.png';
// Get the storage path
$container = FD::cleanPath($this->config->get('links.cache.location'));
$storage = JPATH_ROOT . '/' . $container . '/' . $fileName;
// Check if the file already exists
$exists = JFile::exists($storage);
// If the file is already cached, delete it
if ($exists) {
JFile::delete($storage);
}
// Crawl the image now.
$connector = FD::get('Connector');
$connector->addUrl($imageLink);
$connector->connect();
// Get the result and parse them.
$contents = $connector->getResult($imageLink);
// Store the file to a temporary directory first
$tmpFile = SOCIAL_TMP . '/' . $fileName;
JFile::write($tmpFile, $contents);
// Load the image now
$image = FD::image();
$image->load($tmpFile);
// Ensure that image is valid
if (!$image->isValid()) {
JFile::delete($tmpFile);
return false;
}
// Delete the temporary file.
JFile::delete($tmpFile);
// Unset the image now since we don't want to use asido to resize
unset($image);
// Store the file now into our cache storage.
JFile::write($storage, $contents);
$linkImage->source_url = $imageLink;
$linkImage->internal_url = $fileName;
$linkImage->store();
return $fileName;
}