-
Notifications
You must be signed in to change notification settings - Fork 0
/
pphoto.php
151 lines (129 loc) · 3.91 KB
/
pphoto.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?php
require_once(dirname(__FILE__).'/palbum_object.php');
require_once('settings.php');
class Photo extends AlbumObject implements AlbumObjectInterface {
private $db_id, $filename, $date, $title, $description, $orientation;
public function __construct($id) {
global $db;
if(is_array($id)) {
//IF #id is not photo id (is array), just set it.
$this->db_id = $id['id'];
$this->filename = $id['path_photo'];
$this->filename = $this->filename.$id['filename'];
$this->date = $id['datetaken'];
$this->title = $id['title'];
$this->description = $id['description'];
$this->orientation = $id['orientation'];
} else {
//IF $id is photoid
//Connect DB and fetch one record.
$this->db_id = $id;
$db->query("SELECT * FROM photo_view WHERE id = $1 ORDER BY id;", [$id]);
if($db->isNoResult()) {
throw new Exception("Photo Not Found");
}
$result = $db->result_rows();
$this->filename = $result['path_photo'];
$this->filename = $this->filename.$result['filename'];
$this->date = $result['datetaken'];
$this->title = $result['title'];
$this->description = $result['description'];
$this->orientation = $result['orientation'];
}
}
public function toHTMLthumbnail() {
global $psqlAlbum;
$style = $this->orientationToCSS($this->orientation);
$date = DBConn::date_toJapanese($this->date);
$dir = $psqlAlbum['ThumbnailDir'];
if(!is_null($style)) {
$class = " image_rotated";
} else {
$class = "";
}
return
<<<HEREDOC
<DIV class="album_object">
<A href="index.php?pid=$this->db_id"><IMG class="thumbs$class" style="$style" src="$dir$this->filename" alt="$this->title"></A>
<DIV class="title">$this->title</DIV>
<DIV class="description">$this->description</DIV>
</DIV>
HEREDOC;
}
public function toHTMLlarge() {
global $psqlAlbum;
$style = $this->orientationToCSS($this->orientation);
$date = DBConn::date_toJapanese($this->date);
$dir = $psqlAlbum['PhotoDir'];
return
<<<HEREDOC
<DIV>
<A href="$dir$this->filename"><IMG class="object_large" style="$style" src="$dir$this->filename" alt="$this->title"></A>
<DIV class="title_large">$this->title</DIV>
<DIV class="description_large">$this->description</DIV>
<DIV class="date_large">$date</DIV>
</DIV>
HEREDOC;
}
public static function getObjectsInDateRange($datebegin, $dateend) {
global $db;
$db->query("SELECT id,filename,datetaken,title,description,orientation,path_photo FROM photo_view WHERE datetaken BETWEEN $1 AND $2 ORDER BY id;", [$datebegin, $dateend]);
while($db->hasMoreRows()) {
$result = $db->nextRow();
$photos[] = new Photo($result);
}
if($db->isNoResult()) {
throw new Exception('AlbumObjectNotFound');
}
return $photos;
}
public static function getObjectsBySearchQuery($query) {
global $db;
if($query === "") {
$db->query("SELECT * FROM photo_view ORDER BY id;", []);
} else {
$db->query("SELECT * FROM photo_view WHERE (title LIKE $1 OR description LIKE $1) ORDER BY id;", ["%$query%"]);
}
while($db->hasMoreRows()) {
$result = $db->nextRow();
$photos[] = new Photo($result);
}
if($db->isNoResult()) {
throw new Exception('AlbumObjectNotFound');
}
return $photos;
}
private function orientationToCSS($orientation) {
switch ($orientation) {
case "1":
return;
case "2":
return "transform: rotateX( 180deg );";
case "3":
return "transform: rotate( 180deg );";
case "4":
return "transform: rotateY( 180deg );";
case "5":
return; //Undefined
case "6":
return "transform: rotate( 90deg );";
case "7":
return; //Undefined
case "8":
return "transform: rotate( 270deg );";
}
}
public function getTitle() {
return $this->title;
}
public function getDescription() {
return $this->description;
}
public function getFilename() {
return $this->filename;
}
public function getFileURL() {
global $psqlAlbum;
return $psqlAlbum['AlbumRoot'] . $psqlAlbum['PhotoDir'] . $this->filename;
}
}