Robert Marshall před 10 roky
rodič
revize
fac72b47a7

+ 95 - 95
Controller/Gallery.php

@@ -1,95 +1,95 @@
-<?php
-class Gallery {
-	public function Index($params) {
-		$albums=Album::GetAlbums();
-		return new View("Gallery/index.view",array("albums"=>$albums));
-	}
-	
-	public function View($params) {
-		$album=new Album($params[0],true);
-		Breadcrumbs::Add($album->AlbumTitle, "");
-		return new View("Gallery/view.view",array("album"=>$album));
-	}
-	
-	public function Manage($params) {
-		$vars=array();
-		Breadcrumbs::Add("Manage", "");
-		$vars["albums"]=Album::GetAlbums(true,true);
-		if (isset($params['errors']))
-			$vars["errors"]=$params['errors'];
-		$vars['images']=Image::GetImagesByAlbum(0);
-		if(isset($params['image']))
-			$vars['image']=$params['image'];
-		else
-			$vars['image']=new Image();
-		return new View("Gallery/manage.view",$vars);
-	}
-	
-	public function Move($params){
-		if (!isset($params['moveImages']))
-			return;
-		//return print_r($params,true);
-		foreach ($params['selected'] as $imgId){
-			$image=new Image($imgId);
-			$image->AlbumId=$params['selectAlbumNew'];
-			$image->Save();
-		}
-		header("location:/gallery/manage");
-	}
-	
-	public function CreateAlbum($params) {
-		Breadcrumbs::Add("Manage", "");
-		Breadcrumbs::Add("Create Album", "");
-		$album=new Album();
-		if (isset($params['title']))
-			$album->AlbumTitle=$params['title'];
-		if (isset($params['description']))
-			$album->AlbumDescription=$params['description'];
-		if ($album->AlbumTitle!="" && $album->AlbumDescription!=""){
-			$album->Save();
-			header("location:/gallery/manage");
-			return;
-		}
-		return new View("Gallery/create_album.view",array("album"=>$album));
-	}
-	
-	public function Upload($params) {
-		if (!isset($_FILES['imageFile'])){
-			header("location: /gallery/manage/");
-			return;
-		}
-		$errors=array();
-		$filename=$_FILES['imageFile']['name'];
-		$tempFile=$_FILES['imageFile']['tmp_name'];
-		if ($params['imageTitle']=="")
-			$errors[]="The image doesn't have a title";
-		if ($_FILES['imageFile']['error'])
-			$errors[]=Helper::FileUploadErrorToMessage($_FILES['imageFile']['error']);
-		if (count($errors)==0) {
-			if(!Image::IsValidType(pathinfo($filename,PATHINFO_EXTENSION)))
-				$errors[]="File is of an invalid type";
-			if (getimagesize($tempFile)===false)
-				$errors[]="File is not an image";
-		}
-		$image=new Image($filename,$tempFile);
-		$image->ImageTitle=$params['imageTitle'];
-		$image->ImageDescription=$params['imageDesc'];
-		if (count($errors)==0){
-			$image->Save();
-			header("location: /gallery/manage/");
-			return;
-		}
-		return $this->Manage(array("errors"=>$errors,"image"=>$image));
-	}
-	
-	public function JsonLoadAlbum($params) {
-		$json='[';
-		$images=Image::GetImagesByAlbum($params[0]);
-		foreach ($images as $image)
-			$json.='{"ImageId":"'.$image->ImageId.'","ImageTitle":"'.$image->ImageTitle.'","Path":"'.$image->Path.'","ThumbnailPath":"'.$image->ThumbnailPath.'"},';
-		$json=trim($json,',');
-		$json.=']';
-		return $json;
-		//return json_encode($images);
-	}
-}
+<?php
+class Gallery {
+	public function Index($params) {
+		$albums=Album::GetAlbums();
+		return new View("Gallery/index.view",array("albums"=>$albums));
+	}
+	
+	public function View($params) {
+		$album=new Album($params[0],true);
+		Breadcrumbs::Add($album->AlbumTitle, "");
+		return new View("Gallery/view.view",array("album"=>$album));
+	}
+	
+	public function Manage($params) {
+		$vars=array();
+		Breadcrumbs::Add("Manage", "");
+		$vars["albums"]=Album::GetAlbums(true,true);
+		if (isset($params['errors']))
+			$vars["errors"]=$params['errors'];
+		$vars['images']=Image::GetImagesByAlbum(0);
+		if(isset($params['image']))
+			$vars['image']=$params['image'];
+		else
+			$vars['image']=new Image();
+		return new View("Gallery/manage.view",$vars);
+	}
+	
+	public function Move($params){
+		if (!isset($params['moveImages']))
+			return;
+		//return print_r($params,true);
+		foreach ($params['selected'] as $imgId){
+			$image=new Image($imgId);
+			$image->AlbumId=$params['selectAlbumNew'];
+			$image->Save();
+		}
+		header("location:/gallery/manage");
+	}
+	
+	public function CreateAlbum($params) {
+		Breadcrumbs::Add("Manage", "");
+		Breadcrumbs::Add("Create Album", "");
+		$album=new Album();
+		if (isset($params['title']))
+			$album->AlbumTitle=$params['title'];
+		if (isset($params['description']))
+			$album->AlbumDescription=$params['description'];
+		if ($album->AlbumTitle!="" && $album->AlbumDescription!=""){
+			$album->Save();
+			header("location:/gallery/manage");
+			return;
+		}
+		return new View("Gallery/create_album.view",array("album"=>$album));
+	}
+	
+	public function Upload($params) {
+		if (!isset($_FILES['imageFile'])){
+			header("location: /gallery/manage/");
+			return;
+		}
+		$errors=array();
+		$filename=$_FILES['imageFile']['name'];
+		$tempFile=$_FILES['imageFile']['tmp_name'];
+		if ($params['imageTitle']=="")
+			$errors[]="The image doesn't have a title";
+		if ($_FILES['imageFile']['error'])
+			$errors[]=Utils::FileUploadErrorToMessage($_FILES['imageFile']['error']);
+		if (count($errors)==0) {
+			if(!Image::IsValidType(pathinfo($filename,PATHINFO_EXTENSION)))
+				$errors[]="File is of an invalid type";
+			if (getimagesize($tempFile)===false)
+				$errors[]="File is not an image";
+		}
+		$image=new Image($filename,$tempFile);
+		$image->ImageTitle=$params['imageTitle'];
+		$image->ImageDescription=$params['imageDesc'];
+		if (count($errors)==0){
+			$image->Save();
+			header("location: /gallery/manage/");
+			return;
+		}
+		return $this->Manage(array("errors"=>$errors,"image"=>$image));
+	}
+	
+	public function JsonLoadAlbum($params) {
+		$json='[';
+		$images=Image::GetImagesByAlbum($params[0]);
+		foreach ($images as $image)
+			$json.='{"ImageId":"'.$image->ImageId.'","ImageTitle":"'.$image->ImageTitle.'","Path":"'.$image->Path.'","ThumbnailPath":"'.$image->ThumbnailPath.'"},';
+		$json=trim($json,',');
+		$json.=']';
+		return $json;
+		//return json_encode($images);
+	}
+}

+ 1 - 1
Controller/SettingsEditor.php

@@ -32,7 +32,7 @@ class SettingsEditor {
 		}
 		
 		rename(ApplicationSettings::SETTINGS_PATH, ApplicationSettings::SETTINGS_PATH.(int)microtime(true));
-		Helper::WriteINIFile($newSettings, ApplicationSettings::SETTINGS_PATH, true);
+		Utils::WriteINIFile($newSettings, ApplicationSettings::SETTINGS_PATH, true);
 		
 		header("location:/settingseditor");
 	}

+ 1 - 1
Model/Album.php

@@ -26,7 +26,7 @@ class Album extends DBObjectAutoCreate {
 	
 	public function Save() {
 		if (!isset($this->AlbumUrl) || $this->AlbumUrl==null || $this->AlbumUrl=="")
-			$this->AlbumUrl=Helper::MakeUniqueURL("albums", "album_url", $this->AlbumTitle);
+			$this->AlbumUrl=Utils::MakeUniqueURL("albums", "album_url", $this->AlbumTitle);
 		parent::Save();
 	}
 }

+ 3 - 3
Model/BlogPost.php

@@ -47,7 +47,7 @@ class BlogPost extends DBObjectAutoCreate {
 	
 	public function Save() {
 		if (!isset($this->PostUrl) || $this->PostUrl==null || $this->PostUrl=="")
-			$this->PostUrl=Helper::MakeUniqueURL("blog_posts","post_url",$this->PostTitle);
+			$this->PostUrl=Utils::MakeUniqueURL("blog_posts","post_url",$this->PostTitle);
 		parent::Save();
 	}
 	
@@ -60,10 +60,10 @@ class BlogPost extends DBObjectAutoCreate {
 		$previewLength=ApplicationSettings::GetSetting("blog", "preview_length");
 		$content=$this->PostContent;
 		if ($previewLength<strlen($content)){
-			$pTagPos=strpos($content,"</p>",$previewLength);
+			$pTagPos=strpos($content,"\n",$previewLength);
 			$content=substr($content, 0, $pTagPos);
 		}
-		$content=Helper::CloseOpenTags($content);
+		$content=Utils::CloseOpenTags($content);
 		return $content;
 	}
 	

+ 90 - 90
Model/Image.php

@@ -1,90 +1,90 @@
-<?php
-ApplicationSettings::RegisterDefaultSetting("images", "upload_location", "images/uploads");
-ApplicationSettings::RegisterDefaultSetting("images", "thumbnail_width", "480");
-ApplicationSettings::RegisterDefaultSetting("images", "thumbnail_height", "360");
-
-if (!file_exists(ApplicationSettings::GetSetting("images", "upload_location")))
-	mkdir(ApplicationSettings::GetSetting("images", "upload_location"));
-
-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) {
-		self::CreateTable("images");
-		$images=array();
-		$prep=self::$PDO->prepare("SELECT image_id FROM images WHERE album_id=? AND image_deleted=0");
-		$prep->execute(array($albumId));
-		while ($imageId=$prep->fetchColumn())
-			$images[]=new Image($imageId);
-		return $images;
-	}
-	
-	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(){
-		$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();
-			$this->CalculatePaths();
-			if(!move_uploaded_file($this->TempFile, $this->Path))
-				throw new Exception("Unable to move uploaded file: ".$this->Path.', '.$this->TempFile);
-			
-			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->writeImage($this->ThumbnailPath);
-				$thumb->clear();
-				$thumb->destroy();
-			} else
-				copy($this->Path, $this->ThumbnailPath);
-			
-			parent::Save();
-		}
-	}
-}
+<?php
+ApplicationSettings::RegisterDefaultSetting("images", "upload_location", "images/uploads");
+ApplicationSettings::RegisterDefaultSetting("images", "thumbnail_width", "480");
+ApplicationSettings::RegisterDefaultSetting("images", "thumbnail_height", "360");
+
+if (!file_exists(ApplicationSettings::GetSetting("images", "upload_location")))
+	mkdir(ApplicationSettings::GetSetting("images", "upload_location"));
+
+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) {
+		self::CreateTable("images");
+		$images=array();
+		$prep=self::$PDO->prepare("SELECT image_id FROM images WHERE album_id=? AND image_deleted=0");
+		$prep->execute(array($albumId));
+		while ($imageId=$prep->fetchColumn())
+			$images[]=new Image($imageId);
+		return $images;
+	}
+	
+	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(){
+		$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."_".Utils::MakeStringUrlSafe($this->Filename);
+	}
+	
+	public function Save() {
+		$newSave=!$this->ImageId;
+		parent::Save();
+		if ($newSave && $this->ImageId){
+			$this->ImageFilename=$this->MakeFileName();
+			$this->CalculatePaths();
+			if(!move_uploaded_file($this->TempFile, $this->Path))
+				throw new Exception("Unable to move uploaded file: ".$this->Path.', '.$this->TempFile);
+			
+			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->writeImage($this->ThumbnailPath);
+				$thumb->clear();
+				$thumb->destroy();
+			} else
+				copy($this->Path, $this->ThumbnailPath);
+			
+			parent::Save();
+		}
+	}
+}

+ 2 - 2
Tests/base/HelperTest.php

@@ -38,8 +38,8 @@ class HelperTest extends PHPUnit_Framework_TestCase {
 		$validEmail="rob@robware.uk";
 		$invalidEmail="rob@*";
 		
-		$this->assertEquals(true,Helper::IsValidEmail($validEmail));
-		$this->assertEquals(false,Helper::IsValidEmail($invalidEmail));
+		$this->assertEquals(true,Utils::IsValidEmail($validEmail));
+		$this->assertEquals(false,Utils::IsValidEmail($invalidEmail));
 	}
 
 	/**

+ 6 - 2
base/Helper.php

@@ -1,5 +1,5 @@
 <?php
-class Helper{
+class Utils{
 	const METRES_TO_FEET=3.2808399;
 	const KILOMETRES_TO_MILES=0.621371192;
 	
@@ -79,7 +79,7 @@ class Helper{
 	
 	public static function MakeUniqueURL($table,$field,$string){
 		$PDO=DBObject::GetPDO();
-		$baseUrl=Helper::MakeStringUrlSafe($string);
+		$baseUrl=Utils::MakeStringUrlSafe($string);
 		$prep=$PDO->prepare("SELECT COUNT(*) FROM blog_posts WHERE post_url=?");
 		$prep->execute(array($baseUrl));
 		$found=$prep->fetchColumn()>0;
@@ -178,4 +178,8 @@ class Helper{
 				return "Uknown error";
 		}
 	}
+	
+	public static function FormatMarkupToHTML($input){
+		
+	}
 }