-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathnooMenusAutomaticInstallationBeta.php
299 lines (268 loc) · 12 KB
/
nooMenusAutomaticInstallationBeta.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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
/* @noodom / Automatic menu creation (beta version)
- tag menuName : name of the menu to install (folders from https://github.com/noodom/jeedom_menus)
- Download file /data/menusNoodom/.htAccess
- Download menu files
- Create menu htmlDisplay and content htmlDisplay
- Create menu design (insert menu htmlDisplay and content htmlDisplay)
Menu list :
- menus OK : menuJsonFsb33Frame, menuNooNeumorphism, menuVerticalTom, menuMobileSubMenuFrame, menuNavButton, menuNoo3DAnim, menuNooSliding, menuAnimation, menuInTheAir
- menus KO : menuFloattingDraggable, menuHoverShow
Menu installation details :
- https://github.com/noodom/jeedom_menus/blob/master/installation/nooMenusAutomaticInstallationBeta.php
After installation :
- Menu htmlDisplay not transparent : From design screen, edit design ('Edition'), configure design ('Configurer le design'), configure menu htmlDisplay ('Composants'->'Configuration') and save menu htmlDisplay ('Sauvegarder)
- Problem with design display (loading, css at first launch) : refresh design
- Pensez au café pour les nuits blanches de codage ;) https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=noodom.fr%40gmail.com¤cy_code=EUR&source=url
*/
$tags = $scenario->getTags();
(!isset($tags['#menuName#'])) ? $tags['#menuName#'] = 'menuJsonFsb33Frame' : null;
$menuName = $tags['#menuName#'];
$scenario->setLog('## (Beta) Noodom menu automatic installation : ' . $menuName . ' ##');
$htmldisplayPluginInstalled = true;
try {
$htmldisplayPlugin = plugin::byId('htmldisplay');
}
catch (Exception $e) {
$scenario->setLog("Error : please, install HTML Display plugin");
$htmldisplayPluginInstalled = false;
}
// Plugin HTML Display not installed : installation stopped
if (!$htmldisplayPluginInstalled) {
return;
}
$menuHd = null;
$contentHd = null;
$menuDesign = null;
$suffixName = (strlen(trim($tags['#designSuffixName#'])) > 0) ? $tags['#designSuffixName#'] : '';
$contentHdName = 'noodom_content';
$designName = $suffixName;
$defaultMenuWidth = 1280;
$defaultMenuHeight = 1000;
$menuHdFound = false;
$contentHdFound = false;
$designFound = false;
// Menus folder
$menusFolder = 'menusNoodom';
$originMenuDir = 'https://raw.githubusercontent.com/noodom/jeedom_menus/master/' . $menuName;
// Origin folder and filenames
$originDir = $originMenuDir . '/data/' . $menusFolder;
$originMenuFilename = 'index.html';
$originContentFilename = 'menuFrame.html';
// Destination folder
$destinationDir = '/var/www/html/data/' . $menusFolder;
// Zip menu file
$menuZipFile = $originDir . '/' . $menuName . '.zip';
// Htmldisplay plugin data path
$htmldisplayDatapathDir = '/var/www/html/plugins/htmldisplay/data';
// Create menus folder /menusNoodom
if (!is_file($destinationDir) && !is_dir($destinationDir)) {
$scenario->setLog('Destination dir creation (menus folder) : ' . $destinationDir);
mkdir($destinationDir);
}
// Get .htaccess file
if (is_dir($destinationDir) . '/.') {
$scenario->setLog('** Get .htaccess file');
$originUrl = $originDir . '/.htaccess';
$filename = basename($originUrl);
$save = $destinationDir . '/' . $filename;
$scenario->setLog('- Origin filename : ' . $originUrl);
$scenario->setLog('- Destination filename : ' . $save);
if (file_put_contents($save,file_get_contents($originUrl))) {
$scenario->setLog('- .htaccess downloaded !');
}
}
// Get menu files
$destinationMenu = $destinationDir . '/' . $menuName . $suffixName;
$destinationMenuBackup = $destinationDir . '/' . $menuName . $suffixName . '_backup';
if (is_dir($destinationMenu . '/.')) {
// Delete backup folder
if (is_dir($destinationMenuBackup)) {
$scenario->setLog('** Delete existing menu folder backup : ' . $destinationMenuBackup);
rrmdir($destinationMenuBackup);
}
// Create new backup folder (move existing menu folder)
$scenario->setLog('** Backup existing menu folder : ' . $destinationMenu . ' to ' . $destinationMenuBackup);
rename($destinationMenu,$destinationMenuBackup);
}
if (is_dir($destinationDir)) {
$scenario->setLog('** Get files for menu ' . $menuName);
$scenario->setLog('- Get menu zip file : ' . $menuZipFile);
$destination = $destinationDir . '/temp.zip';
$scenario->setLog('- Destination menu zip file : ' . $destination);
if (!copy($menuZipFile, $destination)) {
$scenario->setLog('/!\ Menu zip file download failed !');
}
else {
$zip = new ZipArchive();
if ($zip->open($destination) === TRUE) {
$scenario->setLog('- Extract files from menu : ' . $menuName);
$zip->extractTo($destinationDir . '/temp');
rename($destinationDir . '/temp/' . $menuName, $destinationDir . '/' . $menuName . $suffixName);
$zip->close();
unlink($destination);
}
}
}
// Create menu and content htmldisplays
$scenario->setLog('** Create menu and content htmldisplays');
$newMenuHdName = $menuName . $suffixName;
$newContentHdName = $contentHdName;
$eqLogics = eqLogic::byType('htmldisplay');
foreach ($eqLogics as $eqLogic) {
// Menu htmlDisplay
if ($eqLogic->getName() == $newMenuHdName) {
$menuHdFound = true;
$menuHd = $eqLogic;
$scenario->setLog('- Menu HD ' . $newMenuHdName . ' found (id:' . $menuHd->getId() . ')');
}
// Content htmlDisplay
if ($eqLogic->getName() == $newContentHdName) {
$contentHdFound = true;
$contentHd = $eqLogic;
$scenario->setLog('- Content HD ' . $newContentHdName . ' found (id:' . $contentHd->getId() . ')');
}
}
if ($menuHdFound == false) {
$menuHd = new htmldisplay();
$menuHd->setName($newMenuHdName);
$menuHd->setEqType_name("htmldisplay");
$menuHd->setIsVisible(1);
$menuHd->setIsEnable(1);
$menuHd->save();
$scenario->setLog('- Menu HD not found : create HD ' . $newMenuHdName . '(id:' . $menuHd->getId() . ')');
}
if ($contentHdFound == false) {
$contentHd = new htmldisplay();
$contentHd->setName($newContentHdName);
$contentHd->setEqType_name("htmldisplay");
$contentHd->setIsVisible(1);
$contentHd->setIsEnable(1);
$contentHd->save();
$scenario->setLog('- Content HD not found : create HD ' . $newContentHdName . '(id:' . $contentHd->getId() . ')');
}
if (is_object($menuHd) && is_object($contentHd)) {
// save menu HD dashboard
$originUrl = $originMenuDir . '/' .$originMenuFilename;
$scenario->setLog('- Save menu HD dashboard from ' . $originUrl);
$filecontent = file_get_contents($originUrl);
$path = $htmldisplayDatapathDir;
if(!file_exists($path)){
mkdir($path);
}
$path .= '/'.$menuHd->getId();
if(!file_exists($path)){
mkdir($path);
}
if (!file_exists($path)) {
$scenario->setLog('Unable to create folder ' . $path);
}
else {
if (!is_writable($path)) {
$scenario->setLog('Unable to write in folder ' . $path);
}
else {
if (!empty($suffixName)) {
$scenario->setLog('- Create specific configuration files for ' . $suffixName);
$scenario->setLog('- Modify perso.css and perso.json links for ' . $suffixName);
$filecontent = str_replace ('data/menusNoodom/' . $menuName, 'data/menusNoodom/' . $menuName . $suffixName, $filecontent);
$filecontent = str_replace ('menuName = "' . $menuName . '"', 'menuName = "' . $menuName . $suffixName . '"', $filecontent);
}
file_put_contents($path.'/dashboard.html', $filecontent);
chmod($path, 0770);
}
}
// save content HD dashboard
$originUrl = $originMenuDir . '/' .$originContentFilename;
$scenario->setLog('- Save content HD dashboard from ' . $originUrl);
$filecontent = file_get_contents($originUrl);
$path = $htmldisplayDatapathDir;
if(!file_exists($path)){
mkdir($path);
}
$path .= '/'.$contentHd->getId();
if(!file_exists($path)){
mkdir($path);
}
if (!file_exists($path)) {
$scenario->setLog('Unable to create folder ' . $path);
}
else {
if (!is_writable($path)) {
$scenario->setLog('Unable to write in folder ' . $path);
}
else {
file_put_contents($path.'/dashboard.html', $filecontent);
chmod($path, 0770);
}
}
}
// Design creation
$newDesignName = $menuName . $designName;
$scenario->setLog('** Create Menu Design ' . $newDesignName);
$planHeaders = planHeader::all();
foreach ($planHeaders as $planHeader) {
//if (!$planHeader->hasRight('r')) {
// continue;
//}
if ($planHeader->getName() == $newDesignName) {
$menuDesign = $planHeader;
$designFound = true;
$scenario->setLog('- Design ' . $newDesignName . ' found : ' . $menuDesign->getId());
}
}
(!isset($tags['#menuDesignWidth#'])) ? $tags['#menuDesignWidth#'] = $defaultMenuWidth : null;
(!isset($tags['#menuDesignHeight#'])) ? $tags['#menuDesignHeight#'] = $defaultMenuHeight : null;
if ($designFound == false) {
// create menu design
$scenario->setLog('- Create design ' . $newDesignName);
$menuDesign = new planHeader();
$menuDesign->setName($newDesignName);
$menuDesign->setId('');
}
$menuDesign->setConfiguration('desktopSizeX', $tags['#menuDesignWidth#']);
$menuDesign->setConfiguration('desktopSizeY', $tags['#menuDesignHeight#']);
$menuDesign->save();
$menuPlans = plan::byPlanHeaderId($menuDesign->getId());
foreach ($menuPlans as $menuPlan) {
if (($menuPlan->getLink_id() != $menuHd->getId()) && ($menuPlan->getLink_id() != $contentHd->getId())) {
$scenario->setLog('- Remove htmldisplay(s) (id:' . $menuPlan->getLink_id() . ') from design ' . $newDesignName . ' (id:' . $menuDesign->getId() . ')');
$menuPlan->remove();
}
}
$menuPlan = plan::byLinkTypeLinkIdPlanHeaderId('eqLogic', $contentHd->getId(), $menuDesign->getId());
//if(count($menuPlan) == 0 || !is_object($menuPlan->getLink())) {
if ($menuPlan == null) {
$scenario->setLog('- add content htmldisplay (id:' . $contentHd->getId() . ')');
$menuPlan = new plan();
$menuPlan->setId('');
$menuPlan->setLink_type('eqLogic');
$menuPlan->setLink_id($contentHd->getId());
$menuPlan->setPlanHeader_id($menuDesign->getId());
$menuPlan->setCss('z-index', 1000);
$menuPlan->save();
}
$menuPlan = plan::byLinkTypeLinkIdPlanHeaderId('eqLogic', $menuHd->getId(), $menuDesign->getId());
//if(count($menuPlan) == 0 || !is_object($menuPlan->getLink())) {
if ($menuPlan == null) {
$scenario->setLog('- add menu htmldisplay (id:' . $menuHd->getId() . ')');
$menuPlan = new plan();
$menuPlan->setId('');
$menuPlan->setLink_type('eqLogic');
$menuPlan->setLink_id($menuHd->getId());
$menuPlan->setPlanHeader_id($menuDesign->getId());
$menuPlan->setDisplay('background-transparent', 1);
$menuPlan->setDisplay('background-defaut', 0);
$menuPlan->setCss('z-index', 1003);
$menuPlan->setCss('background-color', '#000000');
$menuPlan->save();
}
$scenario->setLog('==> Access to the menu ' . $menuName . ' : design id=' . $menuDesign->getId());
$msg = 'Menu généré :: #&l' . 't;a href="/index.php?v=d&p=plan&plan_id=' . $menuDesign->getId() . '&fullscreen=1" target="_blank"&g' . 't;' . $menuName . $suffixName . '&l' . 't;/a&g' . 't;# :'
.' Configuration du menu : #&l' . 't;a href="/data/menusNoodom/' . $menuName . $suffixName . '/json/perso.json" target="_blank"&g' . 't;' . $menuName . $suffixName . '/json/perso.json&l' . 't;/a&g' . 't;# '
. '/ Design #&l' . 't;a href="/index.php?v=d&p=plan&plan_id=' . $menuDesign->getId() . '&fullscreen=1" target="_blank"&g' . 't;' . $menuDesign->getName() . ' (id : ' . $menuDesign->getId() . ')&l' . 't;/a&g' . 't;# '
.'/ htmlDisplay du menu : #&l' . 't;a href="/index.php?v=d&m=htmldisplay&p=htmldisplay&id=' . $menuHd->getId() . '#dashboardtab" target="_blank"&g' . 't;' . $menuHd->getName() . ' (id : ' . $menuHd->getId() . ')&l' . 't;/a&g' . 't;# '
. '/ htmlDisplay du contenu : #&l' . 't;a href="/index.php?v=d&m=htmldisplay&p=htmldisplay&id=' . $contentHd->getId() . '#dashboardtab" target="_blank"&g' . 't;' . $contentHd->getName() . ' (id : ' . $contentHd->getId() . ')&l' . 't;/a&g' . 't;#';
// PR : desktop/modal/message.display.php : $trs .= '<td class="message_action">' . html_entity_decode($message->getAction()) . '</td>';
// $actionMsg = html_entity_decode('#&l' . 't;a href="/index.php?v=d&p=plan&plan_id=' . $menuDesign->getId() . '&fullscreen=1" target="_blank"&g' . 't;Lancer le design&l' . 't;/a&g' . 't;#');
$actionMsg = '';
message::add('Génération de menu Noodom', $msg, $actionMsg, null);