Moved default images (space, user, module) from uploads folder to images

This commit is contained in:
Lucas Bartholemy 2014-07-25 13:35:59 +02:00
parent eba3b81328
commit 1c46ebcc28
9 changed files with 53 additions and 43 deletions

BIN
img/default_banner.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

BIN
img/default_module.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

BIN
img/default_space.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

BIN
img/default_user.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

View File

@ -143,7 +143,7 @@ class HWebModule extends CWebModule
return $this->getAssetsUrl() . '/module_image.png';
}
return Yii::app()->baseUrl . '/uploads/profile_image/default_module.jpg';
return Yii::app()->baseUrl . '/img/default_module.jpg';
}
/**

View File

@ -32,7 +32,8 @@
* @since 0.5
* @author Luke
*/
class ProfileBannerImage {
class ProfileBannerImage
{
/**
* @var String is the guid of user or space
@ -66,7 +67,8 @@ class ProfileBannerImage {
*
* @param type $guid
*/
public function __construct($guid, $defaultImage = 'default') {
public function __construct($guid, $defaultImage = 'default_banner')
{
$this->guid = $guid;
$this->defaultImage = $defaultImage;
}
@ -77,7 +79,8 @@ class ProfileBannerImage {
* @param String $prefix Prefix of the returned image
* @return String Url of the profile image
*/
public function getUrl($prefix = "") {
public function getUrl($prefix = "")
{
$cacheId = 0;
$path = "";
@ -89,15 +92,11 @@ class ProfileBannerImage {
$path = Yii::app()->getBaseUrl(true);
}
$path .= '/uploads/' . $this->folder_images . '/';
$fileName = $this->getPath($prefix);
if (file_exists($fileName)) {
#$cacheId = filemtime($fileName);
if (file_exists($this->getPath($prefix))) {
$path .= '/uploads/' . $this->folder_images . '/';
$path .= $this->guid . $prefix;
} else {
$path .= $this->defaultImage;
$path .= '/img/' . $this->defaultImage;
}
$path .= '.jpg';
@ -110,7 +109,8 @@ class ProfileBannerImage {
*
* @return Boolean is there a profile image
*/
public function hasImage() {
public function hasImage()
{
return file_exists($this->getPath("_org"));
}
@ -120,7 +120,8 @@ class ProfileBannerImage {
* @param String $prefix for the profile image
* @return String Path to the profile image
*/
public function getPath($prefix = "") {
public function getPath($prefix = "")
{
$path = Yii::getPathOfAlias('webroot') . DIRECTORY_SEPARATOR . "uploads" . DIRECTORY_SEPARATOR . $this->folder_images . DIRECTORY_SEPARATOR;
if (!is_dir($path))
@ -142,7 +143,8 @@ class ProfileBannerImage {
* @param Int $w
* @return boolean indicates the success
*/
public function cropOriginal($x, $y, $h, $w) {
public function cropOriginal($x, $y, $h, $w)
{
$image = imagecreatefromjpeg($this->getPath('_org'));
@ -162,17 +164,19 @@ class ProfileBannerImage {
*
* @param CUploadedFile $file
*/
public function setNew($file) {
public function setNew($file)
{
$this->delete();
ImageConverter::TransformToJpeg($file->getTempName(), $this->getPath('_org'));
ImageConverter::Resize($this->getPath('_org'), $this->getPath('_org'), array('width'=>850, 'mode'=>'max'));
ImageConverter::Resize($this->getPath('_org'), $this->getPath(''), array('width'=>$this->width, 'height'=>$this->height));
ImageConverter::Resize($this->getPath('_org'), $this->getPath('_org'), array('width' => 850, 'mode' => 'max'));
ImageConverter::Resize($this->getPath('_org'), $this->getPath(''), array('width' => $this->width, 'height' => $this->height));
}
/**
* Deletes current profile
*/
public function delete() {
public function delete()
{
@unlink($this->getPath());
@unlink($this->getPath('_org'));
}

View File

@ -32,7 +32,8 @@
* @since 0.5
* @author Luke
*/
class ProfileImage {
class ProfileImage
{
/**
* @var String is the guid of user or space
@ -66,7 +67,8 @@ class ProfileImage {
*
* @param type $guid
*/
public function __construct($guid, $defaultImage = 'default') {
public function __construct($guid, $defaultImage = 'default_user')
{
$this->guid = $guid;
$this->defaultImage = $defaultImage;
}
@ -77,7 +79,8 @@ class ProfileImage {
* @param String $prefix Prefix of the returned image
* @return String Url of the profile image
*/
public function getUrl($prefix = "") {
public function getUrl($prefix = "")
{
$cacheId = 0;
$path = "";
@ -89,14 +92,12 @@ class ProfileImage {
$path = Yii::app()->getBaseUrl(true);
}
$path .= '/uploads/' . $this->folder_images . '/';
$fileName = $this->getPath($prefix);
if (file_exists($fileName)) {
#$cacheId = filemtime($fileName);
if (file_exists($this->getPath($prefix))) {
$path .= '/uploads/' . $this->folder_images . '/';
$path .= $this->guid . $prefix;
} else {
$path .= '/img/';
$path .= $this->defaultImage;
}
$path .= '.jpg';
@ -110,7 +111,8 @@ class ProfileImage {
*
* @return Boolean is there a profile image
*/
public function hasImage() {
public function hasImage()
{
return file_exists($this->getPath("_org"));
}
@ -120,7 +122,8 @@ class ProfileImage {
* @param String $prefix for the profile image
* @return String Path to the profile image
*/
public function getPath($prefix = "") {
public function getPath($prefix = "")
{
$path = Yii::getPathOfAlias('webroot') . DIRECTORY_SEPARATOR . "uploads" . DIRECTORY_SEPARATOR . $this->folder_images . DIRECTORY_SEPARATOR;
if (!is_dir($path))
@ -142,7 +145,8 @@ class ProfileImage {
* @param Int $w
* @return boolean indicates the success
*/
public function cropOriginal($x, $y, $h, $w) {
public function cropOriginal($x, $y, $h, $w)
{
$image = imagecreatefromjpeg($this->getPath('_org'));
@ -162,22 +166,24 @@ class ProfileImage {
*
* @param mixed $file CUploadedFile or file path
*/
public function setNew($file) {
public function setNew($file)
{
if ($file instanceof CUploadedFile) {
$file = $file->getTempName();
}
}
$this->delete();
ImageConverter::TransformToJpeg($file, $this->getPath('_org'));
ImageConverter::Resize($this->getPath('_org'), $this->getPath('_org'), array('width'=>400, 'mode'=>'max'));
ImageConverter::Resize($this->getPath('_org'), $this->getPath(''), array('width'=>$this->width, 'height'=>$this->height));
ImageConverter::Resize($this->getPath('_org'), $this->getPath('_org'), array('width' => 400, 'mode' => 'max'));
ImageConverter::Resize($this->getPath('_org'), $this->getPath(''), array('width' => $this->width, 'height' => $this->height));
}
/**
* Deletes current profile
*/
public function delete() {
public function delete()
{
@unlink($this->getPath());
@unlink($this->getPath('_org'));
}

View File

@ -10,14 +10,14 @@
<?php foreach ($modules as $module): ?>
<div class="media">
<?php
$moduleImageUrl = Yii::app()->baseUrl. '/uploads/profile_image/default_module.jpg';
<?php
$moduleImageUrl = Yii::app()->baseUrl. '/img/default_module.jpg';
if (isset($module['moduleImageUrl']) && $module['moduleImageUrl'] != "") {
$moduleImageUrl = $module['moduleImageUrl'];
}
$moduleImageUrl = $module['moduleImageUrl'];
}
?>
<img class="media-object img-rounded pull-left" data-src="holder.js/64x64" alt="64x64"
style="width: 64px; height: 64px;"
src="<?php echo $moduleImageUrl; ?>">

View File

@ -16,7 +16,7 @@
<?php foreach ($modules as $module): ?>
<?php
$moduleImageUrl = Yii::app()->baseUrl . '/uploads/profile_image/default_module.jpg';
$moduleImageUrl = Yii::app()->baseUrl . '/img/default_module.jpg';
if (isset($module['moduleImageUrl']) && $module['moduleImageUrl'] != "") {
$moduleImageUrl = $module['moduleImageUrl'];
}