-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathajax.php
More file actions
102 lines (85 loc) · 2.01 KB
/
ajax.php
File metadata and controls
102 lines (85 loc) · 2.01 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
require_once 'session_init.php';
require_once 'lib/Twig/Autoloader.php';
require_once 'classes/Gallery.php';
require_once 'classes/controller/LoginManager.php';
require_once 'classes/Admin.php';
//require_once 'Twig/Extension.php';
define('MODE_MAIN',0);
define('MODE_DETAIL',1);
define('MODE_SETTINGS',2);
define('MODE_ADMIN',3);
define('DATA_MODE_GET',0);
define('DATA_MODE_POST',1);
$data_mode = -1;
$action = '';
if(isset($_GET['action']))
{
$data_mode = DATA_MODE_GET;
$action = $_GET['action'];
}
if(isset($_POST['action']))
{
$data_mode = DATA_MODE_POST;
$action = $_POST['action'];
}
if($data_mode == -1) die();
class AjaxInterface
{
private $admin;
private $lm;
private $data_mode;
function __construct($data_mode,$admin = false) {
$this->admin = $admin;
$this->lm = new LoginManager();
$this->data_mode = $data_mode;
}
private function getData($name)
{
if($this->data_mode == DATA_MODE_GET)
{
if(isset($_GET[$name]))
return $_GET[$name];
}
else
{
if(isset($_POST[$name]))
return $_POST[$name];
}
throw new RuntimeException("Invalid parameter: $name.");
}
public function action($action)
{
$vars = array();
include 'login.php';
try
{
switch($action)
{
case 'getPhotos':
$g = new Gallery();
$a = new Album($this->getData('album'));
$g->setAlbum($this->getData('album'));
$albumArray = $a->toArray();
if($a->getParent()!=null)
$albumArray['parentCaption'] = $a->getParent()->getCaption();
else
$albumArray['parentCaption'] = '';
$items = array($albumArray);
foreach($g->getItems() as $item)
{
$items[] = $item->toArray();
}
echo json_encode($items);
break;
}
}
catch(Exception $e)
{
echo $e->getMessage();
die();
}
}
} // end of AjaxInterface
$ajaxInterface = new AjaxInterface($data_mode);
$ajaxInterface->action($action);