|
@@ -1,4 +1,5 @@
|
|
|
<?php
|
|
|
+
|
|
|
ApplicationSettings::RegisterDefaultSetting("images", "upload_location", "images/uploads");
|
|
|
ApplicationSettings::RegisterDefaultSetting("images", "thumbnail_width", "480");
|
|
|
ApplicationSettings::RegisterDefaultSetting("images", "thumbnail_height", "360");
|
|
@@ -6,13 +7,14 @@ ApplicationSettings::RegisterDefaultSetting("images", "thumbnail_height", "360")
|
|
|
if (!file_exists(ApplicationSettings::GetSetting("images", "upload_location")))
|
|
|
mkdir(ApplicationSettings::GetSetting("images", "upload_location"));
|
|
|
|
|
|
-class Image extends DBObject {
|
|
|
- public $Path,$ThumbnailPath;
|
|
|
- private $Filename,$TempFile;
|
|
|
-
|
|
|
- public static function IsValidType($ext){
|
|
|
+class Image extends DBObject implements JsonSerializable {
|
|
|
+
|
|
|
+ public $Path, $ThumbnailPath;
|
|
|
+ private $Filename, $TempFile;
|
|
|
+
|
|
|
+ public static function IsValidType($ext) {
|
|
|
// use a switch because it's quicker than a loop
|
|
|
- switch (strtolower($ext)){
|
|
|
+ switch (strtolower($ext)) {
|
|
|
case "bmp":
|
|
|
case "dib":
|
|
|
case "jpeg":
|
|
@@ -29,20 +31,20 @@ class Image extends DBObject {
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- public function __construct($id=0,$tempFile="") {
|
|
|
- if (!is_numeric($id)){
|
|
|
+
|
|
|
+ public function __construct($id=0, $tempFile="") {
|
|
|
+ if (!is_numeric($id)) {
|
|
|
$this->Filename=$id;
|
|
|
$this->TempFile=$tempFile;
|
|
|
$id=0;
|
|
|
}
|
|
|
parent::__construct("images", "image_id", $id);
|
|
|
-
|
|
|
+
|
|
|
if ($this->ImageId)
|
|
|
$this->CalculatePaths();
|
|
|
}
|
|
|
-
|
|
|
- private function CalculatePaths(){
|
|
|
+
|
|
|
+ private function CalculatePaths() {
|
|
|
$dir=ApplicationSettings::GetSetting("images", "upload_location");
|
|
|
$info=pathinfo($this->ImageFilename);
|
|
|
$this->Path=$dir.'/'.$this->ImageFilename;
|
|
@@ -52,22 +54,22 @@ class Image extends DBObject {
|
|
|
private function MakeFileName() {
|
|
|
return $this->ImageId."_".Utils::MakeStringUrlSafe($this->Filename);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public function Save() {
|
|
|
$newSave=!$this->ImageId;
|
|
|
parent::Save();
|
|
|
- if ($newSave && $this->ImageId){
|
|
|
+ if ($newSave&&$this->ImageId) {
|
|
|
$this->ImageFilename=$this->MakeFileName();
|
|
|
$this->CalculatePaths();
|
|
|
- if(!move_uploaded_file($this->TempFile, $this->Path))
|
|
|
+ if (!move_uploaded_file($this->TempFile, $this->Path))
|
|
|
throw new Exception("Unable to move uploaded file: ".$this->Path.', '.$this->TempFile);
|
|
|
-
|
|
|
- if (class_exists("Imagick")){
|
|
|
+
|
|
|
+ if (class_exists("Imagick")) {
|
|
|
$thumb=new Imagick($this->Path);
|
|
|
$height=ApplicationSettings::GetSetting("images", "thumbnail_height");
|
|
|
$width=ApplicationSettings::GetSetting("images", "thumbnail_width");
|
|
|
- $thumb->scaleImage(0,$height);
|
|
|
- $thumb->scaleImage($width,0);
|
|
|
+ $thumb->scaleImage(0, $height);
|
|
|
+ $thumb->scaleImage($width, 0);
|
|
|
$thumb->writeImage($this->ThumbnailPath);
|
|
|
$thumb->clear();
|
|
|
$thumb->destroy();
|
|
@@ -76,4 +78,14 @@ class Image extends DBObject {
|
|
|
parent::Save();
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public function jsonSerialize() {
|
|
|
+ $obj=new stdClass();
|
|
|
+ $obj->path=$this->Path;
|
|
|
+ $obj->thumbnailPath=$this->ThumbnailPath;
|
|
|
+ $obj->imageTitle=$this->ImageTitle;
|
|
|
+ $obj->imageDescription=$this->ImageDescription;
|
|
|
+ return $obj;
|
|
|
+ }
|
|
|
+
|
|
|
}
|