-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbackground.php
More file actions
81 lines (56 loc) · 2.29 KB
/
Copy pathbackground.php
File metadata and controls
81 lines (56 loc) · 2.29 KB
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
<?php
class Controller_Background extends Controller_Rest {
public function before() {
// Throw the exception when invalid request (404 error).
if (!\Input::is_ajax()) {
throw new \Request404Exception();
}
// safely build directory path
$this->directory = DOCROOT . 'assets/img/transitions/';
$this->folder = realpath($this->directory . Input::get('p'));
// set default
if ($this->folder == false) {
$this->folder = 'index';
}
$this->path = $this->directory . basename($this->folder);
$this->js_path = 'assets/img/transitions/' . basename($this->folder);
$this->bg_images = array();
parent::before();
}
public function get_images() {
try {
// Scan directory (jpg and png only)
$images = File::read_dir($this->path, 0, array(
'\.png$' => 'file',
'\.jpg$' => 'file',
)
);
foreach ($images as $image) {
// Build a full file path
$file_path = $this->js_path . '/' .$image;
$this->bg_images[] = $file_path;
}
$this->response(array(
'result' => 'success',
'images' => $this->bg_images
));
}
/*
Invalid path exception, wont throw unless someone is trying to be cheeky
as we supply a default for input and are also using basename and realpath
*/
catch(InvalidPathException $e) {
$this->response(array(
'result' => 'error',
'message' => 'I am an angry exception! Grrrr!'
));
}
// all other exceptions...
catch(Exception $e) {
$this->response(array(
'result' => 'error',
'message' => $e->getMessage()
));
}
}
}