forked from jbroadway/sitellite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
executable file
·183 lines (145 loc) · 4.47 KB
/
index.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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<?php
// BEGIN KEEPOUT CHECKING
// Add these lines to the very top of any file you don't want people to
// be able to access directly.
if (! defined ('SAF_VERSION')) {
header ('HTTP/1.1 404 Not Found');
echo "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n"
. "<html><head>\n<title>404 Not Found</title>\n</head><body>\n<h1>Not Found</h1>\n"
. "The requested URL " . $PHP_SELF . " was not found on this server.<p>\n<hr>\n"
. $_SERVER['SERVER_SIGNATURE'] . "</body></html>";
exit;
}
// END KEEPOUT CHECKING
global $cgi;
loader_import ('cms.Versioning.Rex');
$rex = new Rex ($cgi->collection);
session_set ('imagechooser_path', '/pix');
if (! $rex->collection) {
page_title (intl_get ('Error: Collection not found!'));
echo '<p><a href="' . $_SERVER['HTTP_REFERER'] . '">' . intl_get ('Back') . '</a></p>';
return;
}
if (! session_allowed ('add', 'rw', 'resource')) {
header ('Location: ' . site_prefix () . '/index/cms-cpanel-action');
exit;
}
if (session_is_resource ($cgi->collection) && ! session_allowed ($cgi->collection, 'r', 'resource')) {
header ('Location: ' . site_prefix () . '/index/cms-cpanel-action');
exit;
}
if (isset ($rex->info['Collection']['add'])) {
list ($call, $name) = explode (':', $rex->info['Collection']['add']);
if ($call == 'box') {
echo loader_box ($name);
} elseif ($call == 'form') {
echo loader_form ($name);
} else {
echo loader_form ($call);
}
return;
} else {
class CmsAddForm extends MailForm {
function CmsAddForm () {
parent::MailForm ();
$w =& $this->addWidget ('hidden', 'collection');
$w =& $this->addWidget ('hidden', '_return');
global $cgi;
loader_import ('cms.Versioning.Rex');
$rex = new Rex ($cgi->collection);
$widgets = $rex->getStruct ();
if (! $widgets) {
die ($rex->error);
}
$this->widgets = array_merge ($this->widgets, $widgets);
foreach (array_keys ($this->widgets) as $k) {
if (strtolower (get_class ($this->widgets[$k])) == 'mf_widget_xeditor') {
$this->extra = 'onsubmit="xed_copy_value (this, \'' . $k . '\')"';
}
}
foreach ($rex->info as $k => $v) {
if (preg_match ('/^hint:(.*)$/', $k, $regs)) {
if (! isset ($this->widgets[$regs[1]])) {
$w =& $this->createWidget ($regs[1], $v);
$w->id = $cgi->_key;
}
}
}
if (isset ($rex->info['Collection']['singular'])) {
page_title (intl_get ('Adding') . ' ' . $rex->info['Collection']['singular']);
} else {
page_title (intl_get ('Adding Item'));
}
$w =& $this->addWidget ('msubmit', 'submit_button');
$b =& $w->getButton ();
$b->setValues (intl_get ('Create'));
$b->extra = 'onclick="onbeforeunload_form_submitted = true"';
$b =& $w->addButton ('submit_button', intl_get ('Cancel'));
$b->extra = 'onclick="return cms_cancel (this.form)"';
}
function onSubmit ($vals) {
loader_import ('cms.Versioning.Rex');
$collection = $vals['collection'];
unset ($vals['collection']);
if (empty ($collection)) {
$collection = 'sitellite_page';
}
$return = $vals['_return'];
unset ($vals['_return']);
$rex = new Rex ($collection); // default: database, database
unset ($vals['submit_button']);
foreach ($this->widgets as $k => $w) {
if ($w->type == 'joiner') {
unset ($vals[$k]);
}
}
$res = $rex->create ($vals);
if (isset ($vals[$rex->key]) && $vals[$rex->key] != false) {
$key = $vals[$rex->key];
} elseif (! is_bool ($res)) {
$key = $res;
} else {
$key = 'Unknown';
}
if (! $res) {
if (! $return) {
$return = site_prefix () . '/index/cms-browse-action?collection=' . urlencode ($collection);
}
echo loader_box ('cms/error', array (
'message' => $rex->error,
'collection' => $collection,
'key' => $key,
'action' => $method,
'data' => $vals,
'changelog' => $changelog,
'return' => $return,
));
} else {
foreach ($this->widgets as $k => $w) {
if ($w->type == 'joiner') {
$w->saveSelected ($key);
}
}
loader_import ('cms.Workflow');
echo Workflow::trigger (
'add',
array (
'collection' => $collection,
'key' => $key,
'data' => $vals,
'changelog' => intl_get ('Item added.'),
'message' => 'Collection: ' . $collection . ', Item: ' . $key,
)
);
session_set ('sitellite_alert', intl_get ('Your item has been created.'));
header ('Location: ' . site_prefix () . '/index/cms-browse-action?collection=' . urlencode ($collection));
exit;
}
}
}
//echo CMS_JS_PREVIEW;
echo CMS_JS_CANCEL;
$form = new CmsAddForm;
echo $form->run ();
} // end else
?>