本文整理汇总了PHP中FD::cleanPath方法的典型用法代码示例。如果您正苦于以下问题:PHP FD::cleanPath方法的具体用法?PHP FD::cleanPath怎么用?PHP FD::cleanPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FD
的用法示例。
在下文中一共展示了FD::cleanPath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: upload
/**
* Uploads the given file to a temporary location on the site.
*
* @since 1.0
* @access public
* @param string
* @return string The path to the uploaded item.
*/
public function upload($file, $hash, $userId)
{
// Check if file exists on the server
if (!isset($file['tmp_name']) || empty($file)) {
$this->setError(JText::_('COM_EASYSOCIAL_UPLOADER_FILE_NOT_FOUND'));
return false;
}
// Lets figure out the storage path.
$config = FD::config();
// Test if the folder exists for this upload type.
$path = JPATH_ROOT . '/' . FD::cleanPath($config->get('uploader.storage.container'));
if (!FD::makeFolder($path)) {
$this->setError(JText::sprintf('COM_EASYSOCIAL_UPLOADER_UNABLE_TO_CREATE_DESTINATION_FOLDER', $path));
return false;
}
// Let's finalize the storage path.
$storage = $path . '/' . $userId;
if (!FD::makeFolder($storage)) {
$this->setError(JText::sprintf('COM_EASYSOCIAL_UPLOADER_UNABLE_TO_CREATE_DESTINATION_FOLDER', $storage));
return false;
}
// Once the script reaches here, we assume everything is good now.
// Copy the files over.
jimport('joomla.filesystem.file');
$absolutePath = $storage . '/' . $hash;
if (!JFile::copy($file['tmp_name'], $absolutePath)) {
$this->setError(JText::sprintf('COM_EASYSOCIAL_UPLOADER_UNABLE_TO_COPY_TO_DESTINATION_FOLDER', $absolutePath));
return false;
}
return $absolutePath;
}
示例2: getUrl
/**
* Retrieves the uri for this image
*
* @since 1.3
* @access public
* @param string
* @return
*/
public function getUrl()
{
$config = FD::config();
// Get the container location
$container = FD::cleanPath($config->get('links.cache.location'));
// Relative path to the item
$relativePath = $this->getRelativePath();
// Default base url
$url = rtrim(JURI::root(), '/') . $relativePath;
// Get the storage type for cached images for links
if ($this->storage != 'joomla') {
$storage = FD::storage($this->storage);
$url = $storage->getPermalink($relativePath);
}
return $url;
}
示例3: deleteDefaultAvatars
/**
* Deletes a list of default avatars given the unique id and type.
*
* @since 1.0
* @access public
* @param string
* @return
*/
public function deleteDefaultAvatars($uid, $type = SOCIAL_TYPE_PROFILES)
{
$avatars = $this->getDefaultAvatars($uid, $type);
if (!$avatars) {
return;
}
jimport('joomla.filesystem.folder');
$config = FD::config();
// Build the path to the default avatars.
// Get the default avatars storage location.
$path = JPATH_ROOT . '/' . FD::cleanPath($config->get('avatars.storage.container')) . '/' . FD::cleanPath($config->get('avatars.storage.default'));
$path = $path . '/' . FD::cleanPath($config->get('avatars.storage.defaults.' . $type));
if (!JFolder::exists($path)) {
$this->setError(JText::_('Default avatars path does not exist.'));
return false;
}
$state = JFolder::delete($path);
return $state;
}
示例4: 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;
}
示例5: getStoragePath
/**
* Gets the storage path for photos folder
*
* @since 1.0
* @access public
* @param string
* @return
*/
public function getStoragePath($uid, $type, $createFolders = true)
{
// Construct destination path
$config = FD::config();
// Get initial storage path
$storage = JPATH_ROOT;
// Append it with the container path
$storage = $storage . '/' . FD::cleanPath($config->get('avatars.storage.container'));
// Ensure that the folder exists
if ($createFolders) {
FD::makeFolder($storage);
}
// Append it with the type
$storage = $storage . '/' . FD::cleanPath($config->get('avatars.storage.' . $type));
// Ensure that the folder exists
if ($createFolders) {
FD::makeFolder($storage);
}
// Construct the last segment which contains the uid.
$storage = $storage . '/' . $uid;
// Ensure that the path exists.
if ($createFolders) {
FD::makeFolder($storage);
}
return $storage;
}
示例6: getSource
/**
* Get's the uri to an avatar.
*
* @since 1.0
* @access public
* @param bool Determine if the absolute uri should be returned.
*/
public function getSource($size = SOCIAL_AVATAR_MEDIUM, $absolute = true)
{
$config = FD::config();
// If avatar_id is not empty, means this is this from the default avatars
if (!empty($this->avatar_id)) {
$default = FD::table('defaultavatar');
$default->load($this->avatar_id);
return $default->getSource($size, $absolute);
}
// If the avatar size that is being requested is invalid, return default avatar.
if (!isset($this->{$size}) || empty($this->{$size})) {
return false;
}
// @TODO: Configurable storage path.
$avatarLocation = FD::cleanPath($config->get('avatars.storage.container'));
$typesLocation = FD::cleanPath($config->get('avatars.storage.' . $this->type));
// Build absolute path to the file.
$path = JPATH_ROOT . '/' . $avatarLocation . '/' . $typesLocation . '/' . $this->uid . '/' . $this->{$size};
// Detect if avatar exists.
if (!JFile::exists($path)) {
$default = rtrim(JURI::root(), '/') . $config->get('avatars.default.user.' . $size);
return $default;
}
// Build the uri path for the avatar.
$uri = $avatarLocation . '/' . $typesLocation . '/' . $this->uid . '/' . $this->{$size};
if ($absolute) {
$uri = rtrim(JURI::root(), '/') . '/' . $uri;
}
return $uri;
}
示例7: syncPhotos
/**
* Synchronizes photos from local storage to remote storage.
*
* @since 1.2
* @access public
* @param string
* @return
*/
public function syncPhotos()
{
$storageType = $this->getStorageType();
// If site is configured to storage in joomla, we don't need to do anything
if ($storageType == 'joomla') {
return JText::_('Current photos storage is set to local.');
}
// Load up the storage library
$storage = FD::storage($storageType);
// Get the number of files to process at a time
$limit = $this->getUploadLimit();
// Get a list of photos that failed during the transfer
$exclusion = $this->getFailedObjects('photos');
// Get a list of files to be synchronized over.
$model = FD::model('Photos');
$options = array('pagination' => $limit, 'storage' => SOCIAL_STORAGE_JOOMLA, 'ordering' => 'created', 'sort' => 'asc', 'exclusion' => $exclusion);
// Get a list of photos to sync to amazon
$photos = $model->getPhotos($options);
$total = 0;
if (!$photos) {
return JText::_('No photos to upload to Amazon S3 right now.');
}
// Get list of allowed photos
$allowed = array('thumbnail', 'large', 'square', 'featured', 'medium', 'original', 'stock');
foreach ($photos as $photo) {
// Load the album
$album = FD::table('Album');
$album->load($photo->album_id);
// If the album no longer exists, skip this
if (!$album->id) {
continue;
}
// Get the base path for the album
$basePath = $photo->getStoragePath($album);
$states = array();
// Now we need to get all the available files for this photo
$metas = $model->getMeta($photo->id, SOCIAL_PHOTOS_META_PATH);
// Go through each meta
foreach ($metas as $meta) {
// To prevent some faulty data, we need to manually reconstruct the path here.
$absolutePath = $meta->value;
$file = basename($absolutePath);
$container = FD::cleanPath($this->config->get('photos.storage.container'));
// Reconstruct the path to the source file
$source = JPATH_ROOT . '/' . $container . '/' . $album->id . '/' . $photo->id . '/' . $file;
// To prevent faulty data, manually reconstruct the path here.
$dest = $container . '/' . $album->id . '/' . $photo->id . '/' . $file;
$dest = ltrim($dest, '/');
// We only want to upload certain files
if (in_array($meta->property, $allowed)) {
// Upload the file to the remote storage now
$state = $storage->push($photo->title . $photo->getExtension(), $source, $dest);
// Delete the source file if successfull and configured to do so.
if ($state && $this->deleteable()) {
JFile::delete($source);
}
$states[] = $state;
}
}
$success = !in_array(false, $states);
// If there are no errors, we want to update the storage for the photo
if ($success) {
$photo->storage = $storageType;
$state = $photo->store();
// if photo storage successfully updated to amazon, we need to update the cached object in stream_item.
// Find and update the object from stream_item.
$stream = FD::table('StreamItem');
$options = array('context_type' => SOCIAL_TYPE_PHOTO, 'context_id' => $photo->id);
$exists = $stream->load($options);
if ($exists) {
$stream->params = FD::json()->encode($photo);
$stream->store();
}
$total += 1;
}
// Add this to the storage logs
$this->log($photo->id, 'photos', $success);
}
if ($total > 0) {
return JText::sprintf('%1s photos uploaded to remote storage', $total);
}
return JText::sprintf('No photos to upload to remote storage');
}
示例8: copyAvatar
/**
* Logics to copy default avatars from a profile.
*
* @since 1.1
* @access public
* @author Sam Teh <sam@stackideas.com>
*/
public function copyAvatar($targetProfileId)
{
$avatarsModel = FD::model('Avatars');
$defaultAvatars = $avatarsModel->getDefaultAvatars($targetProfileId);
if ($defaultAvatars) {
foreach ($defaultAvatars as $avatar) {
unset($avatar->id);
$tbl = FD::table('DefaultAvatar');
$tbl->bind($avatar);
$tbl->uid = $this->id;
$tbl->type = SOCIAL_TYPE_PROFILES;
$tbl->created = FD::date()->toMySQL();
$tbl->store();
}
// lets copy the image files.
$config = FD::config();
// Get the avatars storage path.
$avatarsPath = FD::cleanPath($config->get('avatars.storage.container'));
// Get the defaults storage path.
$defaultsPath = FD::cleanPath($config->get('avatars.storage.default'));
// Get the types storage path.
$typesPath = FD::cleanPath($config->get('avatars.storage.defaults.' . SOCIAL_TYPE_PROFILES));
// Get the id storage path
$sourceId = FD::cleanPath($this->uid);
// Let's construct the final path.
$sourcePath = JPATH_ROOT . '/' . $avatarsPath . '/' . $defaultsPath . '/' . $typesPath . '/' . $targetProfileId;
$targetPath = JPATH_ROOT . '/' . $avatarsPath . '/' . $defaultsPath . '/' . $typesPath . '/' . $this->id;
if (JFolder::exists($targetPath)) {
return;
}
// now we are save to copy.
if (JFolder::exists($sourcePath)) {
JFolder::copy($sourcePath, $targetPath);
}
}
}
示例9: getStoragePath
/**
* Returns the file path
*
* @since 1.0
* @access public
* @param string
* @return
*/
public function getStoragePath($relative = false)
{
// Lets figure out the storage path.
$config = FD::config();
$path = '';
if (!$relative) {
$path = JPATH_ROOT;
}
$path .= '/' . FD::cleanPath($config->get('files.storage.container'));
$typePath = $path . '/' . FD::cleanPath($config->get('files.storage.' . $this->type . '.container'));
// Let's finalize the storage path.
$storage = $typePath . '/' . $this->uid;
return $storage;
}
示例10: 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;
}
示例11: removeImage
/**
* Removes phsyical avatar file from the system.
*
* @since 1.0
* @access private
* @param string The size to remove.
* @return bool True on success, false otherwise.
*
* @author Mark Lee <mark@stackideas.com>
*/
private function removeImage($size = SOCIAL_AVATAR_SMALL)
{
jimport('joomla.filesystem.file');
if (!empty($this->{$size})) {
// Build the path to the image item.
$config = FD::config();
$path = JPATH_ROOT;
$path = $path . '/' . FD::cleanPath($config->get('avatars.storage.container'));
$path = $path . '/' . FD::cleanPath($config->get('avatars.storage.default'));
$path = $path . '/' . FD::cleanPath($config->get('avatars.storage.defaults.' . $this->type));
$path = $path . '/' . FD::cleanPath($this->uid);
$path = $path . '/' . $this->{$size};
if (!JFile::exists($path)) {
// dump( $path );
$this->setError(JText::_('COM_EASYSOCIAL_PROFILES_DEFAULT_AVATARS_FILE_NOT_FOUND'));
return false;
}
return JFile::delete($path);
}
return false;
}
示例12: saveCover
public function saveCover(&$post, $uid, $type)
{
$coverData = !empty($post[$this->inputName]) ? $post[$this->inputName] : '';
unset($post[$this->inputName]);
if (empty($coverData)) {
return true;
}
$coverData = FD::makeObject($coverData);
// Get the cover table.
$cover = FD::table('Cover');
// Try to load existing cover
$state = $cover->load(array('uid' => $uid, 'type' => $type));
// If no existing cover, then we set the uid and type.
if (!$state) {
$cover->uid = $uid;
$cover->type = $type;
}
// If both data does not exist, then we don't proceed to store the data.
if (empty($coverData->data) && empty($coverData->position)) {
return true;
}
if (!empty($coverData->data)) {
if ($coverData->data === 'delete') {
$cover->delete();
return true;
}
$coverObj = FD::makeObject($coverData->data);
// Get the cover album.
$album = SocialFieldsUserCoverHelper::getDefaultAlbum($uid, $type);
// Create the photo object.
$photo = SocialFieldsUserCoverHelper::createPhotoObject($uid, $type, $album->id, $coverObj->stock->title, false);
// If there are no cover set for this album, set it as cover.
if (empty($album->cover_id)) {
$album->cover_id = $photo->id;
$album->store();
}
// Construct the path to where the photo is temporarily uploaded.
// $tmpPath = SocialFieldsUserCoverHelper::getPath($this->inputName);
$tmpPath = dirname($coverObj->stock->path);
// Get the supposed path of where the cover should be
// Instead of doing SocialPhotos::getStoragePath, I copied the logic from there but only to create the folders up until albumId section.
// We do not want JPATH_ROOT to be included in the $storage variable
$storage = '/' . FD::cleanPath(FD::config()->get('photos.storage.container'));
FD::makeFolder(JPATH_ROOT . $storage);
$storage .= '/' . $album->id;
FD::makeFolder(JPATH_ROOT . $storage);
$storage .= '/' . $photo->id;
FD::makeFolder(JPATH_ROOT . $storage);
// Copy the photo from the temporary path to the storage folder.
$state = JFolder::copy($tmpPath, JPATH_ROOT . $storage, '', true);
// If cannot copy out the photo, then don't proceed
if ($state !== true) {
$this->setError(JText::_('PLG_FIELDS_COVER_ERROR_UNABLE_TO_MOVE_FILE'));
return false;
}
// Create the photo meta for each available sizes.
foreach ($coverObj as $key => $value) {
SocialFieldsUserCoverHelper::createPhotoMeta($photo, $key, $storage . '/' . $value->file);
}
// Set the uploaded photo as cover for this user.
$cover->setPhotoAsCover($photo->id);
}
// Set the position of the cover if available.
if (!empty($coverData->position)) {
$position = FD::makeObject($coverData->position);
if (isset($position->x)) {
$cover->x = $position->x;
}
if (isset($position->y)) {
$cover->y = $position->y;
}
}
// Store the cover object
$cover->store();
// And we're done.
return true;
}
示例13: getSource
/**
* Retrieves the permalink to the image given the size
*
* @since 1.0
* @access public
* @param string
* @return
*/
public function getSource($type = 'thumbnail')
{
static $paths = array();
$config = FD::config();
// Load the paths for this photo
$model = FD::model('Photos');
$metas = $model->getMeta($this->id, SOCIAL_PHOTOS_META_PATH);
$obj = new stdClass();
$path = FD::cleanPath($config->get('photos.storage.container'));
$allowed = array('thumbnail', 'large', 'original', 'square', 'featured', 'medium');
foreach ($metas as $meta) {
$relative = $path . '/' . $this->album_id . '/' . $this->id . '/' . basename($meta->value);
if ($this->storage != SOCIAL_STORAGE_JOOMLA && in_array($meta->property, $allowed)) {
$storage = FD::storage($this->storage);
$url = $storage->getPermalink($relative);
} else {
$url = rtrim(JURI::root(), '/') . '/' . $relative;
}
$obj->{$meta->property} = $url;
}
$paths[$this->id] = $obj;
if (!isset($paths[$this->id]->{$type})) {
$paths[$this->id]->{$type} = false;
}
return $paths[$this->id]->{$type};
}
示例14: upload
/**
* Responsible to store the uploaded images.
*
* @since 1.0
* @access public
* @param null
*
* @author Mark Lee <mark@stackideas.com>
*/
public function upload($file)
{
// Get config object.
$config = FD::config();
// Do not proceed if image doesn't exist.
if (empty($file) || !isset($file['tmp_name'])) {
$this->setError(JText::_('COM_EASYSOCIAL_PROFILES_DEFAULT_AVATARS_FILE_UNAVAILABLE'));
return false;
}
// 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 default avatars storage location for this type.
$typePath = $config->get('avatars.storage.' . $this->type);
$storagePath = $avatarsPath . '/' . FD::cleanPath($typePath);
// Ensure storage path exists.
if (!FD::makeFolder($storagePath)) {
$this->setError(JText::_('Errors when creating 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()) {
$this->setError(JText::_('COM_EASYSOCIAL_PROFILES_DEFAULT_AVATARS_FILE_NOT_IMAGE'));
return false;
}
// Process avatar storage.
$avatar = FD::get('Avatar', $image);
// Let's create the avatar.
$sizes = $avatar->create($storagePath);
if ($sizes === false) {
$this->setError(JText::_('Sorry, there was some errors when creating the avatars.'));
return false;
}
// Delete previous files.
$this->deleteFile($storagePath);
// Assign the values back.
foreach ($sizes as $size => $url) {
$this->{$size} = $url;
}
return true;
}
示例15: getAvatar
/**
* Retrieves the user's avatar location
*
* @access public
* @param string $size The avatar size to retrieve for.
* @return string The current user's username.
*
* @author Mark Lee <mark@stackideas.com>
*/
public function getAvatar($size = SOCIAL_AVATAR_MEDIUM)
{
$config = FD::config();
// If avatar id is being set, we need to get the avatar source
if ($this->defaultAvatar) {
$default = $this->defaultAvatar->getSource($size);
return $default;
}
// If the avatar size that is being requested is invalid, return default avatar.
$default = $this->getDefaultAvatar($size);
if (!$this->avatars[$size] || empty($this->avatars[$size])) {
return $default;
}
// Get the path to the avatar storage.
$avatarLocation = FD::cleanPath($config->get('avatars.storage.container'));
$usersAvatarLocation = FD::cleanPath($config->get('avatars.storage.user'));
// Build the path now.
$path = $avatarLocation . '/' . $usersAvatarLocation . '/' . $this->id . '/' . $this->avatars[$size];
if ($this->avatarStorage == SOCIAL_STORAGE_JOOMLA) {
// Build final storage path.
$absolutePath = JPATH_ROOT . '/' . $path;
// Detect if this file really exists.
if (!JFile::exists($absolutePath)) {
return $default;
}
$uri = rtrim(JURI::root(), '/') . '/' . $path;
} else {
$storage = FD::storage($this->avatarStorage);
$uri = $storage->getPermalink($path);
}
return $uri;
}