Robert Marshall 10 jaren geleden
bovenliggende
commit
d6c539d617

+ 7 - 0
Controller/E500.php

@@ -0,0 +1,7 @@
+<?php
+class E500{
+	public function Index($params) {
+		return new View("E500/index.view");
+		//return "aaa";
+	}
+}

+ 30 - 1
Controller/Gallery.php

@@ -1,6 +1,35 @@
 <?php
 class Gallery {
 	public function Index($params) {
-		return new View("Gallery/index.view");
+		$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) {
+		Breadcrumbs::Add("Manage", "");
+		$albums=Album::GetAlbums();
+		return new View("Gallery/manage.view",array("albums"=>$albums));
+	}
+	
+	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));
 	}
 }

+ 10 - 0
DB Scripts/create_albums.sql

@@ -0,0 +1,10 @@
+CREATE TABLE `robware-test`.`albums` (
+  `album_id` INT NOT NULL AUTO_INCREMENT,
+  `album_title` VARCHAR(255) NULL,
+  `album_description` TEXT NULL,
+  `album_timestamp` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
+  `album_url` VARCHAR(255) NULL,
+  `album_deleted` BIT NULL DEFAULT 0,
+  `album_hidden` BIT NULL DEFAULT 0,
+  PRIMARY KEY (`album_id`));
+

+ 7 - 4
DB Scripts/create_images.sql

@@ -1,6 +1,9 @@
 CREATE TABLE `robware-test`.`images` (
   `image_id` INT NOT NULL AUTO_INCREMENT,
-  `image_name` TEXT NULL,
-  `image_description` LONGTEXT NULL,
-  `image_file_path` TEXT NULL,
-  PRIMARY KEY (`image_id`));
+  `album_id` INT NULL DEFAULT 0,
+  `image_title` VARCHAR(255) NULL,
+  `image_description` TEXT NULL,
+  `image_timestamp` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
+  `image_deleted` BIT NULL DEFAULT 0,
+  `image_hidden` BIT NULL DEFAULT 1,
+  PRIMARY KEY (`image_id`));

+ 28 - 0
Model/Album.php

@@ -0,0 +1,28 @@
+<?php
+class Album extends DBObjectAutoCreate {
+	public $Images=array();
+	
+	public static function GetAlbums() {
+		self::CreateTable("albums");
+		$albums=array();
+		$albumIds=self::$PDO->query("SELECT album_id FROM albums WHERE album_deleted=0");
+		while ($albumId=$albumIds->fetchColumn())
+			$albums[]=new Album($albumId);
+		return $albums;
+	}
+	
+	public function __construct($id=0,$forceUrl=false) {
+		$field="album_id";
+		if ($forceUrl || !is_numeric($id))
+			$field="album_url";
+		parent::__construct("albums", $field, $id);
+		
+		$this->Images=Image::GetImagesByAlbum($this->AlbumId);
+	}
+	
+	public function Save() {
+		if (!isset($this->AlbumUrl) || $this->AlbumUrl==null || $this->AlbumUrl=="")
+			$this->AlbumUrl=Helper::MakeUniqueURL("albums", "album_url", $this->AlbumTitle);
+		parent::Save();
+	}
+}

+ 1 - 19
Model/BlogPost.php

@@ -47,7 +47,7 @@ class BlogPost extends DBObjectAutoCreate {
 	
 	public function Save() {
 		if (!isset($this->PostUrl) || $this->PostUrl==null || $this->PostUrl=="")
-			$this->MakeUniqueURL();
+			$this->PostUrl=Helper::MakeUniqueURL("blog_posts","post_url",$this->PostTitle);
 		parent::Save();
 	}
 	
@@ -56,24 +56,6 @@ class BlogPost extends DBObjectAutoCreate {
 		$this->Save();
 	}
 	
-	public function MakeUniqueURL(){
-		$baseUrl=Helper::MakeStringUrlSafe($this->PostTitle);
-		$prep=self::$PDO->prepare("SELECT COUNT(*) FROM blog_posts WHERE post_url=?");
-		$prep->execute(array($baseUrl));
-		$found=$prep->fetchColumn()>0;
-		$url=$baseUrl;
-		$count=0;
-		while($found) {
-			$prep->execute(array($url));
-			$found=(int)$prep->fetchColumn()>0;
-			if ($found){
-				$count++;
-				$url=$baseUrl.'-'.$count;
-			}
-		}
-		$this->PostUrl=$url;
-	}
-	
 	public function GetPostPreview() {
 		$previewLength=ApplicationSettings::GetSetting("blog", "preview_length");
 		$content=$this->PostContent;

+ 9 - 0
Model/Image.php

@@ -1,5 +1,14 @@
 <?php
 class Image extends DBObjectAutoCreate {
+	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);
+	}
+	
 	public function __construct($id) {
 		parent::__construct("images", "image_id", $id);
 	}

+ 5 - 0
View/E500/index.view

@@ -0,0 +1,5 @@
+@Title{500 Internal Server Error}@
+@Header{500 Internal Server Error}@
+@Body{
+	It appears there was an error when attempting to load the page.
+}@

+ 17 - 0
View/Gallery/create_album.view

@@ -0,0 +1,17 @@
+@Title{Gallery}@
+@ButtonsRight{
+	<button onclick="Navigate('/gallery/manage/')" title="Manage">
+		<img src="/images/gallery.svg" alt="Manage" />
+	</button><br/>
+	<button type="submit" form="albumForm" title="Save">
+		<img src="/images/save.svg" alt="Save" />
+	</button>
+}@
+@Body{
+	<h3>Title</h3>
+	<form action="" method="post" id="albumForm">
+		<input name="title" style="width:100%" value="<?= htmlspecialchars($album->AlbumTitle) ?>" />
+		<h3>Description</h3>
+		<textarea name="description" style="width:100%; height:100px" ><?= htmlspecialchars($album->AlbumDescription) ?></textarea>
+	</form>
+}@

+ 23 - 76
View/Gallery/index.view

@@ -1,8 +1,10 @@
 @Title{Gallery}@
 @CSS{
 	.album{
-		width:33%;
-		float:left;
+		width:33.33%;
+		/*float:left;*/
+		display:inline-block;
+		vertical-align:top;
 	}
 	
 	.album>div{
@@ -15,11 +17,14 @@
 		display:block;
 		text-align:center;
 		color:#424242;
+		overflow:hidden;
 	}
 }@
 @CSSMed{
-	.album{
-		width:50%;
+	@media(orientation:portrait){
+		.album{
+			width:50%;
+		}
 	}
 }@
 @CSSSmall{
@@ -28,78 +33,20 @@
 			width:100%;
 		}
 	}
+	
+	@media(orientation:landscape){
+		.album{
+			width:50%;
+		}
+	}
+}@
+@ButtonsRight{
+	<button onclick="Navigate('/gallery/manage/')" title="Manage">
+		<img src="/images/gallery.svg" alt="Manage" />
+	</button>
 }@
 @Body{
-	<div class="album">
-		<div>
-			<a href=""><img src="http://uploads.robware.co.uk/Phone%20Camera/IMG_20141209_075310.jpg" /></a>
-			<span>Description aye</span>
-		</div>
-	</div>
-	<div class="album">
-		<div>
-			<a href=""><img src="http://uploads.robware.co.uk/Phone%20Camera/IMG_20141209_075310.jpg" /></a>
-			<span>Description aye</span>
-		</div>
-	</div>
-	<div class="album">
-		<div>
-			<a href=""><img src="http://uploads.robware.co.uk/Phone%20Camera/IMG_20141209_075310.jpg" /></a>
-			<span>Description aye</span>
-		</div>
-	</div>
-	<div class="album">
-		<div>
-			<a href=""><img src="http://uploads.robware.co.uk/Phone%20Camera/IMG_20141209_075310.jpg" /></a>
-			<span>Description aye</span>
-		</div>
-	</div>
-	<div class="album">
-		<div>
-			<a href=""><img src="http://uploads.robware.co.uk/Phone%20Camera/IMG_20141209_075310.jpg" /></a>
-			<span>Description aye</span>
-		</div>
-	</div>
-	<div class="album">
-		<div>
-			<a href=""><img src="http://uploads.robware.co.uk/Phone%20Camera/IMG_20141209_075310.jpg" /></a>
-			<span>Description aye</span>
-		</div>
-	</div>
-	<div class="album">
-		<div>
-			<a href=""><img src="http://uploads.robware.co.uk/Phone%20Camera/IMG_20141209_075310.jpg" /></a>
-			<span>Description aye</span>
-		</div>
-	</div>
-	<div class="album">
-		<div>
-			<a href=""><img src="http://uploads.robware.co.uk/Phone%20Camera/IMG_20141209_075310.jpg" /></a>
-			<span>Description aye</span>
-		</div>
-	</div>
-	<div class="album">
-		<div>
-			<a href=""><img src="http://uploads.robware.co.uk/Phone%20Camera/IMG_20141209_075310.jpg" /></a>
-			<span>Description aye</span>
-		</div>
-	</div>
-	<div class="album">
-		<div>
-			<a href=""><img src="http://uploads.robware.co.uk/Phone%20Camera/IMG_20141209_075310.jpg" /></a>
-			<span>Description aye</span>
-		</div>
-	</div>
-	<div class="album">
-		<div>
-			<a href=""><img src="http://uploads.robware.co.uk/Phone%20Camera/IMG_20141209_075310.jpg" /></a>
-			<span>Description aye</span>
-		</div>
-	</div>
-	<div class="album">
-		<div>
-			<a href=""><img src="http://uploads.robware.co.uk/Phone%20Camera/IMG_20141209_075310.jpg" /></a>
-			<span>Description aye</span>
-		</div>
-	</div>
+	<?php foreach ($albums as $album){
+		echo '<div class="album"><div><a href="/gallery/view/',$album->AlbumUrl,'/"><img src="http://uploads.robware.co.uk/Phone%20Camera/IMG_20141209_075310.jpg" /></a><span>',$album->AlbumTitle,'</span></div></div>';
+	}?>
 }@

+ 52 - 0
View/Gallery/manage.view

@@ -0,0 +1,52 @@
+@Title{Gallery}@
+@CSSSmall{
+	@media(orientation:portrait){
+		td:nth-child(3), th:nth-child(3){
+			display:none;
+		}
+	}
+	td:first-child, th:first-child{
+		display:none;
+	}
+	
+	table{
+		width:100%;
+	}
+	
+	td:last-child,th:last-child,td:nth-child(3), th:nth-child(3){
+		width:1px;
+	}
+}@
+@ButtonsRight{
+	<button onclick="Navigate('/gallery/createalbum/')" title="Create Album">
+		<img src="/images/add_album.svg" alt="Add Album" />
+	</button>
+}@
+@Body{
+<form action="" method="post" id="manageForm">
+	<input type="hidden" name="formSubmitted" value="yes" />
+	<table>
+		<tr>
+			<th>ID</th>
+			<th>Title</th>
+			<th>Timestamp</th>
+			<th>Actions</th>
+		</tr>
+		<?php foreach ($albums as $album){?>
+		<tr>
+			<td><?=$album->AlbumId?></td>
+			<td><a href="/gallery/view/<?=$album->AlbumUrl?>"><?=$album->AlbumTitle?></a></td>
+			<td><?=$album->AlbumTimestamp?></td>
+			<td>
+				<button value="<?=$album->AlbumId?>" name="delete" title="Delete">
+					<img src="/images/delete.svg" alt="Delete" />
+				</button>
+				<button value="/blog/edit/<?=$album->AlbumId?>" name="edit" title="Edit" class="jsNav">
+					<img src="/images/edit.svg" alt="Edit" />
+				</button>
+			</td>
+		</tr>
+		<?php } ?>
+	</table>
+</form>
+}@

+ 4 - 0
View/Gallery/view.view

@@ -0,0 +1,4 @@
+@Title{Gallery}@
+@Body{
+<?=$album->AlbumDescription?>
+}@

+ 19 - 0
base/Helper.php

@@ -77,6 +77,25 @@ class Helper{
 		return $string;
 	}
 	
+	public static function MakeUniqueURL($table,$field,$string){
+		$PDO=DBObject::GetPDO();
+		$baseUrl=Helper::MakeStringUrlSafe($string);
+		$prep=$PDO->prepare("SELECT COUNT(*) FROM blog_posts WHERE post_url=?");
+		$prep->execute(array($baseUrl));
+		$found=$prep->fetchColumn()>0;
+		$url=$baseUrl;
+		$count=0;
+		while($found) {
+			$prep->execute(array($url));
+			$found=(int)$prep->fetchColumn()>0;
+			if ($found){
+				$count++;
+				$url=$baseUrl.'-'.$count;
+			}
+		}
+		return $url;
+	}
+	
 	//stolen (with a few edits) from http://stackoverflow.com/questions/5695145/how-to-read-and-write-to-an-ini-file-with-php
 	public static function WriteINIFile($array,$path,$hasSections){
 		$content="";

+ 11 - 0
images/add_album.svg

@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Generator: Adobe Illustrator 16.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
+<svg version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
+	 width="24px" height="24px" viewBox="0 0 24 24" enable-background="new 0 0 24 24" xml:space="preserve">
+<path fill="none" d="M0,0h24v24H0V0z"/>
+<path fill="#4CAF50" enable-background="new    " d="M4,6H2v14c0,1.1,0.9,2,2,2h14v-2H4V6z"/>
+<path fill="#66BB6A" d="M22,4v12c0,1.1-0.9,2-2,2H8c-1.1,0-2-0.9-2-2V4c0-1.1,0.9-2,2-2h12C21.1,2,22,2.9,22,4z"/>
+<path opacity="0.7" fill="#4CAF50" enable-background="new    " d="M22,4v12c0,1.1-0.9,2-2,2h-6.04V2H20C21.1,2,22,2.9,22,4z"/>
+<polygon fill="#FFFFFF" points="19,11 15,11 15,15 13,15 13,11 9,11 9,9 13,9 13,5 15,5 15,9 19,9 "/>
+</svg>

+ 11 - 0
images/gallery.svg

@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Generator: Adobe Illustrator 16.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
+<svg version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
+	 width="24px" height="24px" viewBox="0 0 24 24" enable-background="new 0 0 24 24" xml:space="preserve">
+<path fill="none" d="M0,0h24v24H0V0z"/>
+<path fill="#B3E5FC" d="M22,4v12c0,1.1-0.9,2-2,2H8c-1.1,0-2-0.9-2-2V4c0-1.1,0.9-2,2-2h12C21.1,2,22,2.9,22,4z"/>
+<path fill="#81D4FA" d="M22,4v12c0,1.1-0.9,2-2,2h-6.03V2H20C21.1,2,22,2.9,22,4z"/>
+<polygon fill="#66BB6A" points="11,12 13.029,14.71 16,11 20,16 8,16 "/>
+<path fill="#81D4FA" d="M2,6v14c0,1.1,0.9,2,2,2h14v-2H4V6H2z"/>
+</svg>