-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontenthandler.php
205 lines (185 loc) · 7.14 KB
/
contenthandler.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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
<?php
require ('pagehandler.php');
require ('generalsettings.php');
if (!$_SERVER["REQUEST_METHOD"] == "POST") {
//die(); DONT REMOVE THIS COMMENT OR THINGS MIGHT BREAK
}
if (!empty($_POST["action"])) {
$action = $_POST["action"];
switch ($action) {
case "loadWidgets":
loadWidgets();
break;
}
}
/**
* Insert a HTML container with $widgets[$widgetIndex] inside of it
* If "edit" mode is true, it adds a + button in the top left of a widget,
* and (when it exists) inserts the special edit version of a widget
* @param array $widgets
* @param int $widgetIndexI
*/
function insertWidgetContainer(array $widgets, int $widgetIndex, int $height) {
$widgetName = $widgets[$widgetIndex - 1];
$edit = $_POST["edit"];
if ($widgetName == "empty") {
?>
<div class="widget-container empty-widget w-100 h-100 mx-auto my-auto <?= $edit == true ? 'border' : '' ?>" style="height: <?= $height ?>px;">
<img id="<?= $widgetIndex ?>" class="plus-icon add-widget-plus-button" src="images/plus-solid.svg">
</div>
<?php
}
/* The code BELOW will create HTML that looks like this:
* <div id="$widgetIndex" class="widget-container w-100 h-100 border">
<h1 id="$widgetIndex" class="plus-icon add-widget-plus-button">+</h1> (ONLY IF EDIT MODE == TRUE)
<div id="$widgetName" class="widget-content mx-auto my-auto">
--- here is the content of the widget ---
</div>
</div>
*/
else {
?>
<div id="<?= $widgetIndex ?>" class="widget-container w-100 <?= $edit == true ? 'border' : '' ?> page-<?= $_POST["pageName"] ?>" style="height: <?= $height ?>px;">
<? if ($edit == true): ?>
<img id="<?= $widgetIndex ?>" class="plus-icon-small add-widget-plus-button" src="images/plus-solid.svg">
<? endif; ?>
<div id="<?= $widgetName ?>" class="widget-content mx-auto my-auto">
<input type="hidden" name="widget-index" value="<?= $widgetIndex ?>">
<input type="hidden" name="pageName" value="<?= $_POST["pageName"] ?>">
<?
// If in edit mode (aka admin adding widgets):
// Select widgetname-edit.php to get the editor version
// Or the regular widgetname.php if a special edit version does not exist
if ($edit == false) {
// THIS IS HOW WIDGETS GET INSERTED FROM THEIR OWN PHP file
require 'widgets/' . $widgetName . '/' . $widgetName . '.php';
}
else {
if (file_exists('widgets/' . $widgetName . '/' . $widgetName . '-edit.php')) {
require 'widgets/' . $widgetName . '/' . $widgetName . '-edit.php';
}
else require 'widgets/' . $widgetName . '/' . $widgetName . '.php';
} ?>
</div>
</div>
<?php
}
}
// This is used on display.php so I don't have to do stupid AJAX post requests
function loadWidgetsFromArguments($edit, $pageName) {
$_POST["edit"] = $edit;
$_POST["pageName"] = $pageName;
echo loadWidgets();
}
/**
* Create page layout with HTML / bootstrap, then use insertWidgetContainer() to insert the widget itself into the page
* Then return the layout as a whole
*/
function loadWidgets() {
$edit = $_POST["edit"];
$pageName = $_POST["pageName"];
$page = getPage($pageName);
$widgets = $page->widgets;
$smallHeight = 475;
$tallHeight = $smallHeight * 2;
if ($page->getLayoutAsString() == "1") {
?>
<div class="row" style="height: <?=$tallHeight?>px">
<div class="col-12">
<? insertWidgetContainer($widgets, 1, $tallHeight); ?>
</div>
</div>
<?php
}
else if ($page->getLayoutAsString() == "2-horizontal") {
?>
<div class="row" style="height: <?=$smallHeight?>px;">
<div class="col-12">
<? insertWidgetContainer($widgets, 1, $smallHeight); ?>
</div>
</div>
<div class="row" style="height: <?=$smallHeight?>px;">
<div class="col-12">
<? insertWidgetContainer($widgets, 2, $smallHeight); ?>
</div>
</div>
<?php
}
else if ($page->getLayoutAsString() == "2-vertical") {
?>
<div class="row" style="height: <?=$tallHeight?>px;">
<div class="col-6">
<? insertWidgetContainer($widgets, 1, $tallHeight); ?>
</div>
<div class="col-6">
<? insertWidgetContainer($widgets, 2, $tallHeight); ?>
</div>
</div>
<?php
}
else if ($page->getLayoutAsString() == "1-2") {
?>
<div class="row" style="height: <?=$tallHeight?>px;">
<div class="col-6">
<? insertWidgetContainer($widgets, 1, $tallHeight); ?>
</div>
<div class="col-6">
<div class="row" style="height: <?=$smallHeight?>px;">
<div class="col-12">
<? insertWidgetContainer($widgets, 2, $smallHeight); ?>
</div>
</div>
<div class="row" style="height: <?=$smallHeight?>px;">
<div class="col-12">
<? insertWidgetContainer($widgets, 3, $smallHeight); ?>
</div>
</div>
</div>
</div>
<?php
}
else if ($page->getLayoutAsString() == "2-1") {
?>
<div class="row" style="height: <?=$tallHeight?>px">
<div class="col-6">
<div class="row" style="height: <?=$smallHeight?>px;">
<div class="col-12">
<? insertWidgetContainer($widgets, 1, $smallHeight); ?>
</div>
</div>
<div class="row" style="height: <?=$smallHeight?>px;">
<div class="col-12">
<? insertWidgetContainer($widgets, 2, $smallHeight); ?>
</div>
</div>
</div>
<div class="col-6">
<? insertWidgetContainer($widgets, 3, $tallHeight); ?>
</div>
</div>
<?php
}
else if ($page->getLayoutAsString() == "4") {
?>
<div class="row" style="height: <?=$smallHeight?>px;">
<div class="col-6">
<? insertWidgetContainer($widgets, 1, $smallHeight); ?>
</div>
<div class="col-6">
<? insertWidgetContainer($widgets, 2, $smallHeight); ?>
</div>
</div>
<div class="row" style="height: <?=$smallHeight?>px;">
<div class="col-6">
<? insertWidgetContainer($widgets, 3, $smallHeight); ?>
</div>
<div class="col-6">
<? insertWidgetContainer($widgets, 4, $smallHeight); ?>
</div>
</div>
<?php
}
?>
<input id="pageLayoutHiddenInput" type="hidden" name="pageLayout" value="<?= $page->getLayoutAsString(); ?>">
<?php
}