automatisch-fotoalbum
Let op: dit is niet het gehele script!
Code (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
152
153
154
155
156
157
158
159
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
152
153
154
155
156
157
158
159
<?php
/**
* index.php
*
*/
function galleryAutoload($cls_name){
require_once str_replace('_','/',$cls_name).'.php';
}
spl_autoload_register('galleryAutoload');
$gallery = new Lib_Gallery();
$gallery->dispatch();
/**
* Lib/Gallery.php
*
*/
class Lib_Gallery {
/**
* Enter description here...
*
* @var array
*/
protected $options = array(
'dir' => 'photos/',
'thumb' => array( // Thumbs options
'dir' => 'thumbs/', // in the $this->options['dir'] dir
'size' => 150
),
'medium' => array( // Medium photo size options
'dir' => 'medium/', // in the $this->options['dir'] dir
'size' => 500
),
'orig' => array( // The origional photos
'dir' => 'orig/' // in the $this->options['dir'] dir
),
'extensions' => array('.jpg','.gif','.png','.jpeg'), // lowercase file extension
'view_options' => array( // The view options
'dir' => 'templates/' // The template dir
),
'photos_per_page' => 12,
'gallery_title' => 'My Gallery'
);
/**
* The params parsed from the URL
*
* @var array
*/
protected $urlParams = array();
/**
* The view object / template parser
*
* @var Lib_Template_Interface
*/
protected $view;
public function __construct($options=null){
if(is_array($options)){
$this->setOptions($options);
}elseif(!empty($options)){
throw new InvalidArgumentException('The $options argument must be an array or must be empty');
}
$this->urlParams = (array) $_GET;
}
/**
* Set the options recursively
*
* @param array $options
* @param int $level (recursive level)
* @return array
*/
protected function setOptions(array $options,$level=0){
$newOptions = array();
foreach($options as $key => $option){
if(is_array($option)){
$newOptions[$key] = $this->setOptions($option,$level++);
}else{
$newOptions[$key] = $option;
}
}
if($level === 0){
$this->options = $newOptions;
}
return $newOptions;
}
/**
* Set the URL params.
* By default the $this->urlParams is the $_GET array
*
* @param array $params
*/
public function setUrlParams(array $params){
$this->urlParams = $params;
}
/**
* If you would like to use smarty/dwoo or an other template engine.
* you can extend smarty en implement Lib_Template_Interface and use
* smarty/dwoo/templatepower
*
* @param Lib_Template_Interface $view
*/
public function setView(Lib_Template_Interface $view){
$this->view = $view;
}
/**
* Return or show the gallery
*
* @param bool $return
*/
public function dispatch($return = false){
if(!($this->view instanceof Lib_Template_Interface)){
$this->view = new Lib_Template($this->options['view_options']);
}
if(!empty($this->urlParams['dir']) && !empty($this->urlParams['photo'])){
// A dir and a photo is selected
$page = new Lib_Gallery_Photo($this->urlParams['dir'],$this->urlParams['photo']);
}elseif(!empty($this->urlParams['dir'])){
// only a dir is selected
$page = new Lib_Gallery_Dir($this->urlParams['dir']);
}else{
// Nothing at all is selected
$page = new Lib_Gallery_Albums();
}
if($page instanceof Lib_Gallery_Page_Interface){
$page->setOptions($this->options);
$page->setUrlParams($this->urlParams);
$page->setView($this->view);
$page->init();
if($return){
return $page->fetch();
}else{
echo $page->fetch();
}
}else{
throw new Exception(get_class($page).' is not an instance of Lib_Gallery_Page_Interface');
}
}
}
?>
/**
* index.php
*
*/
function galleryAutoload($cls_name){
require_once str_replace('_','/',$cls_name).'.php';
}
spl_autoload_register('galleryAutoload');
$gallery = new Lib_Gallery();
$gallery->dispatch();
/**
* Lib/Gallery.php
*
*/
class Lib_Gallery {
/**
* Enter description here...
*
* @var array
*/
protected $options = array(
'dir' => 'photos/',
'thumb' => array( // Thumbs options
'dir' => 'thumbs/', // in the $this->options['dir'] dir
'size' => 150
),
'medium' => array( // Medium photo size options
'dir' => 'medium/', // in the $this->options['dir'] dir
'size' => 500
),
'orig' => array( // The origional photos
'dir' => 'orig/' // in the $this->options['dir'] dir
),
'extensions' => array('.jpg','.gif','.png','.jpeg'), // lowercase file extension
'view_options' => array( // The view options
'dir' => 'templates/' // The template dir
),
'photos_per_page' => 12,
'gallery_title' => 'My Gallery'
);
/**
* The params parsed from the URL
*
* @var array
*/
protected $urlParams = array();
/**
* The view object / template parser
*
* @var Lib_Template_Interface
*/
protected $view;
public function __construct($options=null){
if(is_array($options)){
$this->setOptions($options);
}elseif(!empty($options)){
throw new InvalidArgumentException('The $options argument must be an array or must be empty');
}
$this->urlParams = (array) $_GET;
}
/**
* Set the options recursively
*
* @param array $options
* @param int $level (recursive level)
* @return array
*/
protected function setOptions(array $options,$level=0){
$newOptions = array();
foreach($options as $key => $option){
if(is_array($option)){
$newOptions[$key] = $this->setOptions($option,$level++);
}else{
$newOptions[$key] = $option;
}
}
if($level === 0){
$this->options = $newOptions;
}
return $newOptions;
}
/**
* Set the URL params.
* By default the $this->urlParams is the $_GET array
*
* @param array $params
*/
public function setUrlParams(array $params){
$this->urlParams = $params;
}
/**
* If you would like to use smarty/dwoo or an other template engine.
* you can extend smarty en implement Lib_Template_Interface and use
* smarty/dwoo/templatepower
*
* @param Lib_Template_Interface $view
*/
public function setView(Lib_Template_Interface $view){
$this->view = $view;
}
/**
* Return or show the gallery
*
* @param bool $return
*/
public function dispatch($return = false){
if(!($this->view instanceof Lib_Template_Interface)){
$this->view = new Lib_Template($this->options['view_options']);
}
if(!empty($this->urlParams['dir']) && !empty($this->urlParams['photo'])){
// A dir and a photo is selected
$page = new Lib_Gallery_Photo($this->urlParams['dir'],$this->urlParams['photo']);
}elseif(!empty($this->urlParams['dir'])){
// only a dir is selected
$page = new Lib_Gallery_Dir($this->urlParams['dir']);
}else{
// Nothing at all is selected
$page = new Lib_Gallery_Albums();
}
if($page instanceof Lib_Gallery_Page_Interface){
$page->setOptions($this->options);
$page->setUrlParams($this->urlParams);
$page->setView($this->view);
$page->init();
if($return){
return $page->fetch();
}else{
echo $page->fetch();
}
}else{
throw new Exception(get_class($page).' is not an instance of Lib_Gallery_Page_Interface');
}
}
}
?>