本文整理汇总了PHP中EB::image方法的典型用法代码示例。如果您正苦于以下问题:PHP EB::image方法的具体用法?PHP EB::image怎么用?PHP EB::image使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EB
的用法示例。
在下文中一共展示了EB::image方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getImage
/**
* Retrieves the blog image to be used as the twitter image
*
* @since 4.0
* @access public
* @param string
* @return
*/
public static function getImage(EasyBlogPost &$blog)
{
$config = EB::config();
// First, we try to search to see if there's a blog image. If there is already, just ignore the rest.
if ($blog->getImage('thumbnail')) {
return $blog->getImage('thumbnail');
}
// @legacy: If there's no image for this blog post, then we do this the legacy way.
// First let's try to find for an image.
$img = '';
$pattern = '#<img[^>]*>#i';
preg_match($pattern, $blog->content, $matches);
if ($matches) {
$img = $matches[0];
} else {
$text = $blog->intro;
preg_match($pattern, $text, $matches);
if ($matches) {
$img = $matches[0];
}
}
// Default image
$source = '';
//image found. now we process further to get the absolute image path.
if ($img) {
//get the img source
$pattern = '/src=[\\"\']?([^\\"\']?.*(png|jpg|jpeg|gif))[\\"\']?/i';
preg_match($pattern, $img, $matches);
if ($matches) {
$imgPath = $matches[1];
$source = EB::image()->rel2abs($imgPath, JURI::root());
}
}
return $source;
}
示例2: getImage
public static function getImage(EasyBlogPost &$blog, $rawIntroText = '')
{
// First, we try to search to see if there's a blog image. If there is already, just ignore the rest.
if ($blog->hasImage()) {
return $blog->getImage('large', true, true);
}
// For image posts.
if (isset($blog->images[0])) {
return $blog->images[0];
}
// If there's no image for this blog post, then we do this the legacy way.
// First let's try to find for an image.
$img = '';
$pattern = '#<img[^>]*>#i';
preg_match($pattern, $blog->content, $matches);
if ($matches) {
$img = $matches[0];
} else {
$category = $blog->getPrimaryCategory();
$text = $category->getParam('main_hideintro_entryview') ? $rawIntroText : $blog->intro;
preg_match($pattern, $text, $matches);
if ($matches) {
$img = $matches[0];
}
}
// Get the image source
$pattern = '/src=[\\"\']?([^\\"\']?.*(png|jpg|jpeg|gif))[\\"\']?/i';
preg_match($pattern, $img, $matches);
if ($matches) {
$imgPath = $matches[1];
$source = EB::image()->rel2abs($imgPath, JURI::root());
return $source;
}
// Default post image if the blog post doesn't contain any image
$app = JFactory::getApplication();
$override = JPATH_ROOT . '/templates/' . $app->getTemplate() . '/html/com_easyblog/images/placeholder-facebook.png';
if (JFile::exists($override)) {
$source = rtrim(JURI::root(), '/') . '/templates/' . $app->getTemplate() . '/html/com_easyblog/images/placeholder-facebook.png';
} else {
$source = rtrim(JURI::root(), '/') . '/components/com_easyblog/themes/wireframe/images/placeholder-facebook.png';
}
return $source;
}
示例3: upload
/**
* Handles uploads from media manager.
*
* @since 4.0
* @access public
* @param string
* @return
*/
public function upload()
{
// Ensure that the user is logged in
EB::requireLogin();
// Only allowed users who are allowed to upload images
if (!$this->acl->get('upload_image')) {
$this->output(EB::exception('COM_EASYBLOG_NOT_ALLOWED', EASYBLOG_MSG_ERROR));
}
// Load up media manager
$mm = EB::mediamanager();
// Get uri
$key = $this->input->getRaw('key');
// Get the target folder
$placeId = EBMM::getUri($key);
// Get the file input
$file = $this->input->files->get('file');
// Check if the file is really allowed to be uploaded to the site.
$state = EB::image()->canUploadFile($file);
if ($state instanceof Exception) {
return $this->output($state);
}
// MM should check if the user really has access to upload to the target folder
$allowed = EBMM::hasAccess($placeId);
if ($allowed instanceof Exception) {
return $this->output($allowed);
}
// Check the image name is it got contain space, if yes need to replace to '-'
$fileName = $file['name'];
$file['name'] = str_replace(' ', '-', $fileName);
// Upload the file now
$file = $mm->upload($file, $placeId);
// Response object is intended to also include
// other properties like status message and status code.
// Right now it only inclues the media item.
$response = new stdClass();
$response->media = EBMM::getMedia($file->uri);
return $this->output($response);
}
示例4: getAvatar
/**
* Retrieves the avatar url
*
* @since 4.0
* @access public
* @param string
* @return
*/
public function getAvatar($profile)
{
$path = JPATH_ROOT . '/' . EB::image()->getAvatarRelativePath() . '/' . $profile->avatar;
$image = EB::image()->getAvatarRelativePath() . '/' . $profile->avatar;
$app = JFactory::getApplication();
$link = $image;
$default = 'components/com_easyblog/assets/images/default_blogger.png';
// Check for default overrides
$overrides = JPATH_ROOT . '/templates/' . $app->getTemplate() . '/html/com_easyblog/assets/images/default_blogger.png';
$exists = JFile::exists($overrides);
if (!$profile->avatar) {
if ($exists) {
$link = 'templates/' . $app->getTemplate() . '/html/com_easyblog/assets/images/default_blogger.png';
} else {
$link = $default;
}
}
if ($profile->avatar == 'default_blogger.png') {
$link = $default;
}
$link = rtrim(JURI::root(), '/') . '/' . $link;
return $link;
}
示例5: getAvatar
/**
* Retrieve categories avatar
*
* @since 4.0
* @access public
* @return string The location to the avatar
*/
public function getAvatar()
{
$defaults = array('cdefault.png', 'default_category.png', 'components/com_easyblog/assets/images/default_category.png', 'components/com_easyblog/assets/images/cdefault.png');
$link = 'components/com_easyblog/assets/images/default_category.png';
if (!in_array($this->avatar, $defaults) && !empty($this->avatar)) {
$link = EB::image()->getAvatarRelativePath('category') . '/' . $this->avatar;
}
return rtrim(JURI::root(), '/') . '/' . $link;
}
示例6: getFirstImage
public static function getFirstImage($content)
{
//try to search for the 1st img in the blog
$img = '';
$pattern = '#<img[^>]*>#i';
preg_match($pattern, $content, $matches);
if ($matches) {
$img = $matches[0];
}
//image found. now we process further to get the absolute image path.
if (!empty($img)) {
//get the img src
$pattern = '/src\\s*=\\s*"(.+?)"/i';
preg_match($pattern, $img, $matches);
if ($matches) {
$imgPath = $matches[1];
$imgSrc = EB::image()->rel2abs($imgPath, JURI::root());
return $imgSrc;
}
}
return false;
}
示例7: uploadMedia
/**
* Stores the media object that is sent from the xmlrpc client
*
* @since 5.0
* @access public
* @param string
* @return
*/
public static function uploadMedia($blogid, $username, $password, $file)
{
global $xmlrpcerruser, $xmlrpcI4, $xmlrpcInt, $xmlrpcBoolean, $xmlrpcDouble, $xmlrpcString, $xmlrpcDateTime, $xmlrpcBase64, $xmlrpcArray, $xmlrpcStruct, $xmlrpcValue;
// Login the user
$state = self::login($username, $password);
if ($state !== true) {
return $state;
}
// Get the config
$config = EB::config();
// Get the user's acl
$acl = EB::acl();
// Get the current user
$my = JFactory::getUser();
// Check if user has permissions to upload images
if (!$acl->get('upload_image')) {
return new xmlrpcresp(0, $xmlrpcerruser + 2, JText::_('You do not have permissions to upload files to the site.'));
}
// Get the main image storage path
$path = rtrim($config->get('main_image_path'), '/');
$relativePath = $path . '/' . $my->id;
$absolutePath = JPATH_ROOT . '/' . $path . '/' . $my->id;
$absolutePath = JPath::clean($absolutePath);
$absoluteUri = rtrim(JURI::root(), '/') . '/' . str_ireplace('\\', '/', $relativePath) . '/' . $my->id;
// If the user's folder doesn't exist yet, create it first.
if (!JFolder::exists($absolutePath)) {
JFolder::create($absolutePath);
}
// Set the temporary folder
$tmp = JPATH_ROOT . '/tmp';
$mediamanager = EB::mediamanager();
// Normalize the file name
$file['name'] = $mediamanager->normalizeFileName($file['name']);
// Write the file to the
$tmpFile = $tmp . '/' . $file['name'];
JFile::write($tmpFile, $file['bits']);
// Enter some dummy data so we can run some sanity checks on the file
$file['tmp_name'] = $tmpFile;
$file['size'] = 0;
$error = '';
$allowed = EB::image()->canUploadFile($file, $error);
// If file uploads aren't allowed for some reasons, we need to revert
if ($allowed !== true) {
JFile::delete($file['tmp_name']);
return new xmlrpcresp(0, $xmlrpcerruser + 1, $error);
}
// Ensure that the image goes through the media manager resizing format
$result = $mediamanager->upload($file);
// Once it's gone through media manager, delete the temporary file
JFile::delete($file['tmp_name']);
// Build the url for the xmlrpc client so that they can replace the links accordingly within the content
$url = rtrim(JURI::root(), '/') . '/' . $relativePath . '/' . $file['name'];
return new xmlrpcresp(new xmlrpcval(array('url' => new xmlrpcval($url)), 'struct'));
}
示例8: getAndRemoveImages
public static function getAndRemoveImages($content)
{
//try to search for the 1st img in the blog
$img = '';
$pattern = '#<img[^>]*>#i';
$result = array();
preg_match($pattern, $content, $matches);
if (isset($matches[0]) && !empty($matches[0])) {
$images = $matches[0];
if (!is_array($images)) {
$images = array($images);
}
foreach ($images as $image) {
$content = str_ireplace($image, '', $content);
// Get the URL to the image
$pattern = '/src=[\\"\']?([^\\"\']?.*(png|jpg|jpeg|gif))[\\"\']?/i';
preg_match($pattern, $image, $matches);
if ($matches) {
$imgPath = $matches[1];
$source = EB::image()->rel2abs($imgPath, JURI::root());
$result[] = $source;
}
}
}
$obj = new stdClass();
$obj->content = $content;
$obj->images = $result;
return $obj;
}
示例9: uploadImage
public function uploadImage($key)
{
// Load up media manager
$mm = EB::mediamanager();
// Get the target folder
$placeId = EBMM::getUri($key);
// Get the file input
$file = JRequest::getVar('file', '', 'FILES', 'array');
// Check if the file is really allowed to be uploaded to the site.
$state = EB::image()->canUploadFile($file);
if ($state instanceof Exception) {
//add error code
return $state;
//return $this->output($state);
}
// MM should check if the user really has access to upload to the target folder
$allowed = EBMM::hasAccess($placeId);
if ($allowed instanceof Exception) {
//add error code
return $state;
//return $this->output($allowed);
}
// Check the image name is it got contain space, if yes need to replace to '-'
$fileName = $file['name'];
$file['name'] = str_replace(' ', '-', $fileName);
// Upload the file now
$file = $mm->upload($file, $placeId);
// Response object is intended to also include
// other properties like status message and status code.
// Right now it only inclues the media item.
$response = new stdClass();
$response->media = EBMM::getMedia($file->uri);
//code for future use
//header('Content-type: text/x-json; UTF-8');
//$resp = json_encode($response, JSON_HEX_TAG);
return $response;
}
示例10: upload
/**
* Uploads a user avatar
*
* @since 4.0
* @access public
* @param string
* @return
*/
public function upload($fileData, $userId = false)
{
jimport('joomla.filesystem.file');
jimport('joomla.filesystem.folder');
// Check if the user is allowed to upload avatar
$acl = EB::acl();
// Ensure that the user really has access to upload avatar
if (!$acl->get('upload_avatar')) {
$this->setError('COM_EASYBLOG_NO_PERMISSION_TO_UPLOAD_AVATAR');
return false;
}
// Get the current user
$user = JFactory::getUser();
// If there is userId passed, means this is from backend.
// We cannot get the current logged in user because it will always be the admin.
if ($userId) {
$user = JFactory::getUser($userId);
}
$app = JFactory::getApplication();
$config = EB::config();
$path = $config->get('main_avatarpath');
$path = rtrim($path, '/');
$relativePath = $path;
$absolutePath = JPATH_ROOT . '/' . $path;
// If the absolute path does not exist, create it first
if (!JFolder::exists($absolutePath)) {
JFolder::create($absolutePath);
// Copy the index.html file over to this new folder
JFile::copy(JPATH_ROOT . '/components/com_easyblog/index.html', $absolutePath . '/index.html');
}
// The file data should have a name
if (!isset($fileData['name'])) {
return false;
}
// Generate a better name for the file
$fileData['name'] = $user->id . '_' . JFile::makeSafe($fileData['name']);
// Get the relative path
$relativeFile = $relativePath . '/' . $fileData['name'];
// Get the absolute file path
$absoluteFile = $absolutePath . '/' . $fileData['name'];
// Test if the file is upload-able
$message = '';
if (!EB::image()->canUpload($fileData, $message)) {
$this->setError($message);
return false;
}
// Determines if the web server is generating errors
if ($fileData['error'] != 0) {
$this->setError($fileData['error']);
return false;
}
// We need to delete the old avatar
$profile = EB::user($user->id);
// Get the old avatar
$oldAvatar = $profile->avatar;
$isNew = false;
// Delete the old avatar first
if ($oldAvatar != 'default.png' && $oldAvatar != 'default_blogger.png') {
$session = JFactory::getSession();
$sessionId = $session->getToken();
$oldAvatarPath = $absolutePath . '/' . $oldAvatar;
if (JFile::exists($oldAvatarPath)) {
JFile::delete($oldAvatarPath);
}
} else {
$isNew = true;
}
$width = EBLOG_AVATAR_LARGE_WIDTH;
$height = EBLOG_AVATAR_LARGE_HEIGHT;
$image = EB::simpleimage();
$image->load($fileData['tmp_name']);
$image->resizeToFill($width, $height);
$image->save($absoluteFile, $image->type);
if ($isNew && $config->get('main_jomsocial_userpoint')) {
EB::jomsocial()->assignPoints('com_easyblog.avatar.upload', $user->id);
}
return $fileData['name'];
}
示例11: getAvatar
/**
* Retrieves the team blog's avatar
*
* @since 4.0
* @access public
* @return string
*/
public function getAvatar()
{
// Default team blog avatar
$link = '/components/com_easyblog/assets/images/default_teamblog.png';
if ($this->avatar) {
// Construct the relative path to the avatar
$link = '/' . EB::image()->getAvatarRelativePath('team') . '/' . $this->avatar;
}
// Reconstruct with the site url
$link = rtrim(JURI::root(), '/') . $link;
return $link;
}