|
@@ -1,5 +1,33 @@
|
|
<?php
|
|
<?php
|
|
|
|
+ApplicationSettings::RegisterDefaultSetting("images", "upload_location", "images/uploads");
|
|
|
|
+ApplicationSettings::RegisterDefaultSetting("images", "thumbnail_width", "480");
|
|
|
|
+ApplicationSettings::RegisterDefaultSetting("images", "thumbnail_height", "360");
|
|
|
|
+
|
|
|
|
+
|
|
class Image extends DBObjectAutoCreate {
|
|
class Image extends DBObjectAutoCreate {
|
|
|
|
+ public $Path,$ThumbnailPath;
|
|
|
|
+ private $Filename,$TempFile;
|
|
|
|
+
|
|
|
|
+ public static function IsValidType($ext){
|
|
|
|
+ // use a switch because it's quicker than a loop
|
|
|
|
+ switch (strtolower($ext)){
|
|
|
|
+ case "bmp":
|
|
|
|
+ case "dib":
|
|
|
|
+ case "jpeg":
|
|
|
|
+ case "jpg":
|
|
|
|
+ case "jpe":
|
|
|
|
+ case "jfif":
|
|
|
|
+ case "gif":
|
|
|
|
+ case "tif":
|
|
|
|
+ case "tiff":
|
|
|
|
+ case "png":
|
|
|
|
+ case "ico":
|
|
|
|
+ return true;
|
|
|
|
+ default:
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
public static function GetImagesByAlbum($albumId) {
|
|
public static function GetImagesByAlbum($albumId) {
|
|
self::CreateTable("images");
|
|
self::CreateTable("images");
|
|
$images=array();
|
|
$images=array();
|
|
@@ -7,9 +35,38 @@ class Image extends DBObjectAutoCreate {
|
|
$prep->execute(array($albumId));
|
|
$prep->execute(array($albumId));
|
|
while ($imageId=$prep->fetchColumn())
|
|
while ($imageId=$prep->fetchColumn())
|
|
$images[]=new Image($imageId);
|
|
$images[]=new Image($imageId);
|
|
|
|
+ return $images;
|
|
}
|
|
}
|
|
|
|
|
|
- public function __construct($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);
|
|
parent::__construct("images", "image_id", $id);
|
|
|
|
+
|
|
|
|
+ if ($this->ImageId){
|
|
|
|
+ $dir=ApplicationSettings::GetSetting("images", "upload_location");
|
|
|
|
+ $info=pathinfo($this->ImageFilename);
|
|
|
|
+ $this->Path=$dir.'/'.$this->ImageFilename;
|
|
|
|
+ $this->ThumbnailPath=$dir.'/'.$info['filename'].'.thumbnail.'.$info['extension'];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private function MakeFileName() {
|
|
|
|
+ return $this->ImageId."_".Helper::MakeStringUrlSafe($this->Filename);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function Save() {
|
|
|
|
+ $newSave=!$this->ImageId;
|
|
|
|
+ parent::Save();
|
|
|
|
+ if ($newSave && $this->ImageId){
|
|
|
|
+ $this->ImageFilename=$this->MakeFileName();
|
|
|
|
+ $imageDir=ApplicationSettings::GetSetting("images", "upload_location");
|
|
|
|
+ if(!move_uploaded_file($this->TempFile, $imageDir.'/'.$this->ImageFilename))
|
|
|
|
+ throw new Exception("Unable to move uploaded file: ".$imageDir.'/'.$this->ImageFilename.', '.$this->TempFile);
|
|
|
|
+ parent::Save();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|