Bearsampp 2025.8.29
Loading...
Searching...
No Matches
class.tpl.app.php
Go to the documentation of this file.
1<?php
2/*
3 * Copyright (c) 2021-2024 Bearsampp
4 * License: GNU General Public License version 3 or later; see LICENSE.txt
5 * Author: Bear
6 * Website: https://bearsampp.com
7 * Github: https://github.com/Bearsampp
8 */
9
17class TplApp
18{
19 // Constants for item and section identifiers
20 const ITEM_CAPTION = 0;
21 const ITEM_GLYPH = 1;
22
23 const SECTION_CALL = 0;
24 const SECTION_CONTENT = 1;
25
29 private function __construct()
30 {
31 }
32
43 public static function process()
44 {
45 global $bearsamppCore;
46
47 return TplAestan::getSectionConfig() . PHP_EOL .
48 self::getSectionServices() . PHP_EOL .
52 TplAestan::getSectionMenuLeftSettings(APP_TITLE . ' ' . $bearsamppCore->getAppVersion()) . PHP_EOL .
53 self::getSectionMenuRight() . PHP_EOL .
54 self::getSectionMenuLeft() . PHP_EOL;
55 }
56
64 public static function processLight()
65 {
66 return TplAestan::getSectionConfig() . PHP_EOL .
67 self::getSectionServices() . PHP_EOL .
70 }
71
80 public static function getSectionName($name, $args = array())
81 {
82 return ucfirst($name) . (!empty($args) ? '-' . md5(serialize($args)) : '');
83 }
84
94 public static function getSectionContent($name, $class, $args = array())
95 {
96 $baseMethod = 'get' . ucfirst($name);
97 $args = $args == null ? array() : $args;
98 return '[' . self::getSectionName($name, $args) . ']' . PHP_EOL .
99 call_user_func_array($class . '::' . $baseMethod, $args);
100 }
101
115 public static function getActionRun($action, $args = array(), $item = array(), $waitUntilTerminated = true)
116 {
118 $args = $args == null ? array() : $args;
119
120 $argImp = '';
121 foreach ($args as $arg) {
122 $argImp .= ' ' . base64_encode($arg);
123 }
124
125 $result = 'Action: run; ' .
126 'FileName: "' . $bearsamppCore->getPhpExe(true) . '"; ' .
127 'Parameters: "' . Core::isRoot_FILE . ' ' . $action . $argImp . '"; ' .
128 'WorkingDir: "' . $bearsamppRoot->getCorePath(true) . '"';
129
130 if (!empty($item)) {
131 $result = 'Type: item; ' . $result .
132 '; Caption: "' . $item[self::ITEM_CAPTION] . '"' .
133 (!empty($item[self::ITEM_GLYPH]) ? '; Glyph: "' . $item[self::ITEM_GLYPH] . '"' : '');
134 } elseif ($waitUntilTerminated) {
135 $result .= '; Flags: waituntilterminated';
136 }
137
138 return $result;
139 }
140
152 public static function getActionMulti($action, $args = array(), $item = array(), $disabled = false, $class = false)
153 {
154 $action = 'action' . ucfirst($action);
155 $args = $args == null ? array() : $args;
156 $sectionName = self::getSectionName($action, $args);
157
158 $call = 'Action: multi; Actions: ' . $sectionName;
159
160 if (!empty($item)) {
161 $call = 'Type: item; ' . $call .
162 '; Caption: "' . $item[self::ITEM_CAPTION] . '"' .
163 (!empty($item[self::ITEM_GLYPH]) ? '; Glyph: "' . $item[self::ITEM_GLYPH] . '"' : '');
164 } else {
165 $call .= '; Flags: waituntilterminated';
166 }
167
168 return array($call, self::getSectionContent($action, $class, $args));
169 }
170
176 public static function getActionExec()
177 {
178 return self::getActionRun(Action::EXEC, array(), array(), false);
179 }
180
190 public static function getMenu($caption, $menu, $class)
191 {
192 $menu = 'menu' . ucfirst($menu);
193
194 $call = 'Type: submenu; ' .
195 'Caption: "' . $caption . '"; ' .
196 'SubMenu: ' . self::getSectionName($menu) . '; ' .
198
199 return array($call, self::getSectionContent($menu, $class, null));
200 }
201
212 public static function getMenuEnable($caption, $menu, $class, $enabled = true)
213 {
214 $menu = 'menu' . ucfirst($menu);
215
216 $call = 'Type: submenu; ' .
217 'Caption: "' . $caption . '"; ' .
218 'SubMenu: ' . self::getSectionName($menu) . '; ' .
220
221 return array($call, self::getSectionContent($menu, $class, null));
222 }
223
231 private static function getSectionServices()
232 {
233 global $bearsamppBins;
234
235 $result = '[Services]' . PHP_EOL;
236 foreach ($bearsamppBins->getServices() as $service) {
237 $result .= 'Name: ' . $service->getName() . PHP_EOL;
238 }
239
240 return $result;
241 }
242
248 private static function getSectionStartupAction()
249 {
250 return '[StartupAction]' . PHP_EOL .
254 self::getActionExec() . PHP_EOL;
255 }
256
264 private static function getSectionMenuRight()
265 {
266 global $bearsamppLang;
267
268 $tplReload = TplAppReload::process();
269 $tplBrowser = TplAppBrowser::process();
270 $tplLang = TplAppLang::process();
271 $tplLogsVerbose = TplAppLogsVerbose::process();
272 $tplLaunchStartup = TplAppLaunchStartup::process();
273 $tplExit = TplAppExit::process();
274
275 return
276 // Items
277 '[Menu.Right]' . PHP_EOL .
283 ) . PHP_EOL .
285
286 TplAestan::getItemSeparator() . PHP_EOL .
287 TplAppClearFolders::process() . PHP_EOL .
288 TplAppRebuildIni::process() . PHP_EOL .
289 $tplReload[self::SECTION_CALL] . PHP_EOL .
290
291 TplAestan::getItemSeparator() . PHP_EOL .
292 $tplBrowser[self::SECTION_CALL] . PHP_EOL .
293 TplAppEditConf::process() . PHP_EOL .
294 $tplLang[self::SECTION_CALL] . PHP_EOL .
295 $tplLogsVerbose[self::SECTION_CALL] . PHP_EOL .
296
297 TplAestan::getItemSeparator() . PHP_EOL .
298 $tplLaunchStartup[self::SECTION_CALL] . PHP_EOL .
299 $tplExit[self::SECTION_CALL] . PHP_EOL .
300
301 // Actions
302 PHP_EOL . $tplBrowser[self::SECTION_CONTENT] . PHP_EOL .
303 PHP_EOL . $tplLang[self::SECTION_CONTENT] .
304 PHP_EOL . $tplLaunchStartup[self::SECTION_CONTENT] .
305 PHP_EOL . $tplLogsVerbose[self::SECTION_CONTENT] .
306 PHP_EOL . $tplReload[self::SECTION_CONTENT] . PHP_EOL .
307 PHP_EOL . $tplExit[self::SECTION_CONTENT] . PHP_EOL;
308 }
309
319 private static function getSectionMenuLeft()
320 {
322
323 $tplApache = TplAppApache::process();
324 $tplMailpit = TplAppMailpit::process();
325 $tplMariadb = TplAppMariadb::process();
326 $tplMemcached = TplAppMemcached::process();
327 $tplMysql = TplAppMysql::process();
328 $tplNodejs = TplAppNodejs::process();
329 $tplPhp = TplAppPhp::process();
330 $tplPostgresql = TplAppPostgresql::process();
331 $tplXlight = TplAppXlight::process();
332
333 $tplApps = TplAppApps::process();
334 $tplLogs = TplAppLogs::process();
335 $tplTools = TplAppTools::process();
336
337 $tplServices = TplAppServices::process();
338
339 $tplOnline = TplAppOnline::process();
340
341 $httpUrl = 'http://localhost' . ($bearsamppBins->getApache()->getPort() != 80 ? ':' . $bearsamppBins->getApache()->getPort() : '');
342 $httpsUrl = 'https://localhost' . ($bearsamppBins->getApache()->getSslPort() != 443 ? ':' . $bearsamppBins->getApache()->getSslPort() : '');
343
344 return
345 // Items
346 '[Menu.Left]' . PHP_EOL .
347 TplAestan::getItemLink($bearsamppLang->getValue(Lang::MENU_LOCALHOST), $httpUrl) . PHP_EOL .
348 TplAestan::getItemLink($bearsamppLang->getValue(Lang::MENU_LOCALHOST) . ' (SSL)', $httpsUrl) . PHP_EOL .
350
352 TplAestan::getItemSeparator() . PHP_EOL .
353 $tplApache[self::SECTION_CALL] . PHP_EOL .
354 $tplMailpit[self::SECTION_CALL] . PHP_EOL .
355 $tplMariadb[self::SECTION_CALL] . PHP_EOL .
356 $tplMemcached[self::SECTION_CALL] . PHP_EOL .
357 $tplMysql[self::SECTION_CALL] . PHP_EOL .
358 $tplNodejs[self::SECTION_CALL] . PHP_EOL .
359 $tplPhp[self::SECTION_CALL] . PHP_EOL .
360 $tplPostgresql[self::SECTION_CALL] . PHP_EOL .
361 $tplXlight[self::SECTION_CALL] . PHP_EOL .
362
364 TplAestan::getItemSeparator() . PHP_EOL .
365 $tplApps[self::SECTION_CALL] . PHP_EOL .
366 $tplLogs[self::SECTION_CALL] . PHP_EOL .
367 $tplTools[self::SECTION_CALL] . PHP_EOL .
368
370 TplAestan::getItemSeparator() . PHP_EOL .
371 $tplServices[self::SECTION_CALL] .
372
374 TplAestan::getItemSeparator() . PHP_EOL .
375 $tplOnline[self::SECTION_CALL] . PHP_EOL .
376
377 // Actions
378 PHP_EOL . $tplApache[self::SECTION_CONTENT] .
379 PHP_EOL . $tplMailpit[self::SECTION_CONTENT] .
380 PHP_EOL . $tplMariadb[self::SECTION_CONTENT] .
381 PHP_EOL . $tplMemcached[self::SECTION_CONTENT] .
382 PHP_EOL . $tplMysql[self::SECTION_CONTENT] .
383 PHP_EOL . $tplNodejs[self::SECTION_CONTENT] .
384 PHP_EOL . $tplPhp[self::SECTION_CONTENT] .
385 PHP_EOL . $tplPostgresql[self::SECTION_CONTENT] .
386 PHP_EOL . $tplXlight[self::SECTION_CONTENT] .
387 PHP_EOL . $tplApps[self::SECTION_CONTENT] .
388 PHP_EOL . $tplLogs[self::SECTION_CONTENT] .
389 PHP_EOL . $tplTools[self::SECTION_CONTENT] .
390 PHP_EOL . $tplServices[self::SECTION_CONTENT] .
391 PHP_EOL . $tplOnline[self::SECTION_CONTENT];
392 }
393}
$result
global $bearsamppBins
global $bearsamppLang
global $bearsamppRoot
global $bearsamppCore
const CHECK_VERSION
const ABOUT
const EXEC
const STARTUP
const isRoot_FILE
const MENU_LOCALHOST
const MENU_ABOUT
const MENU_CHECK_UPDATE
const HELP
const MENU_WWW_DIRECTORY
static getSectionConfig()
const GLYPH_FOLDER_DISABLED
const GLYPH_FOLDER_CLOSE
static getSectionMessages()
static getSectionMenuLeftSettings($caption)
static getItemExplore($caption, $path)
static getItemLink($caption, $link, $local=false, $glyph=self::GLYPH_WEB_PAGE)
static getSectionMenuRightSettings()
static getItemSeparator()
static getSectionStartupAction()
static getActionMulti($action, $args=array(), $item=array(), $disabled=false, $class=false)
static getMenu($caption, $menu, $class)
static getSectionMenuLeft()
static getSectionName($name, $args=array())
const ITEM_GLYPH
static getSectionMenuRight()
static processLight()
static process()
static getSectionContent($name, $class, $args=array())
static getActionRun($action, $args=array(), $item=array(), $waitUntilTerminated=true)
static getSectionServices()
const SECTION_CALL
const SECTION_CONTENT
const ITEM_CAPTION
static getActionExec()
static getMenuEnable($caption, $menu, $class, $enabled=true)
static getWebsiteUrl($path='', $fragment='', $utmSource=true)
const APP_TITLE
Definition root.php:13