Bearsampp 2026.7.11
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: "' . Path::getPhpExe(true) . '"; ' .
127 'Parameters: "' . Core::isRoot_FILE . ' ' . $action . $argImp . '"; ' .
128 'WorkingDir: "' . Path::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 .
284 TplAestan::getItemLink($bearsamppLang->getValue(Lang::DOCUMENTATION), 'https://documentation.bearsampp.com/') . PHP_EOL .
285 TplAestan::getItemLink('FAQ', HttpClient::getWebsiteUrl('documentation/faqs')) . PHP_EOL .
286
287 TplAestan::getItemSeparator() . PHP_EOL .
288 TplAppClearFolders::process() . PHP_EOL .
289 TplAppRebuildIni::process() . PHP_EOL .
290 $tplReload[self::SECTION_CALL] . PHP_EOL .
291
292 TplAestan::getItemSeparator() . PHP_EOL .
293 $tplBrowser[self::SECTION_CALL] . PHP_EOL .
294 TplAppEditConf::process() . PHP_EOL .
295 $tplLang[self::SECTION_CALL] . PHP_EOL .
296 $tplLogsVerbose[self::SECTION_CALL] . PHP_EOL .
297
298 TplAestan::getItemSeparator() . PHP_EOL .
299 $tplLaunchStartup[self::SECTION_CALL] . PHP_EOL .
300 $tplExit[self::SECTION_CALL] . PHP_EOL .
301
302 // Actions
303 PHP_EOL . $tplBrowser[self::SECTION_CONTENT] . PHP_EOL .
304 PHP_EOL . $tplLang[self::SECTION_CONTENT] .
305 PHP_EOL . $tplLaunchStartup[self::SECTION_CONTENT] .
306 PHP_EOL . $tplLogsVerbose[self::SECTION_CONTENT] .
307 PHP_EOL . $tplReload[self::SECTION_CONTENT] . PHP_EOL .
308 PHP_EOL . $tplExit[self::SECTION_CONTENT] . PHP_EOL;
309 }
310
320 private static function getSectionMenuLeft()
321 {
323
324 $tplApache = TplAppApache::process();
325 $tplMailpit = TplAppMailpit::process();
326 $tplMariadb = TplAppMariadb::process();
327 $tplMemcached = TplAppMemcached::process();
328 $tplMysql = TplAppMysql::process();
329 $tplNodejs = TplAppNodejs::process();
330 $tplPhp = TplAppPhp::process();
331 $tplPostgresql = TplAppPostgresql::process();
332 $tplXlight = TplAppXlight::process();
333
334 $tplApps = TplAppApps::process();
335 $tplLogs = TplAppLogs::process();
336 $tplTools = TplAppTools::process();
337
338 $tplServices = TplAppServices::process();
339
340 $tplOnline = TplAppOnline::process();
341
342 $httpUrl = 'http://localhost' . ($bearsamppBins->getApache()->getPort() != 80 ? ':' . $bearsamppBins->getApache()->getPort() : '');
343 $httpsUrl = 'https://localhost' . ($bearsamppBins->getApache()->getSslPort() != 443 ? ':' . $bearsamppBins->getApache()->getSslPort() : '');
344
345 return
346 // Items
347 '[Menu.Left]' . PHP_EOL .
348 TplAestan::getItemLink($bearsamppLang->getValue(Lang::MENU_LOCALHOST), $httpUrl) . PHP_EOL .
349 TplAestan::getItemLink($bearsamppLang->getValue(Lang::MENU_LOCALHOST) . ' (SSL)', $httpsUrl) . PHP_EOL .
351
353 TplAestan::getItemSeparator() . PHP_EOL .
354 $tplApache[self::SECTION_CALL] . PHP_EOL .
355 $tplMailpit[self::SECTION_CALL] . PHP_EOL .
356 $tplMariadb[self::SECTION_CALL] . PHP_EOL .
357 $tplMemcached[self::SECTION_CALL] . PHP_EOL .
358 $tplMysql[self::SECTION_CALL] . PHP_EOL .
359 $tplNodejs[self::SECTION_CALL] . PHP_EOL .
360 $tplPhp[self::SECTION_CALL] . PHP_EOL .
361 $tplPostgresql[self::SECTION_CALL] . PHP_EOL .
362 $tplXlight[self::SECTION_CALL] . PHP_EOL .
363
365 TplAestan::getItemSeparator() . PHP_EOL .
366 $tplApps[self::SECTION_CALL] . PHP_EOL .
367 $tplLogs[self::SECTION_CALL] . PHP_EOL .
368 $tplTools[self::SECTION_CALL] . PHP_EOL .
369
371 TplAestan::getItemSeparator() . PHP_EOL .
372 $tplServices[self::SECTION_CALL] .
373
375 TplAestan::getItemSeparator() . PHP_EOL .
376 $tplOnline[self::SECTION_CALL] . PHP_EOL .
377
378 // Actions
379 PHP_EOL . $tplApache[self::SECTION_CONTENT] .
380 PHP_EOL . $tplMailpit[self::SECTION_CONTENT] .
381 PHP_EOL . $tplMariadb[self::SECTION_CONTENT] .
382 PHP_EOL . $tplMemcached[self::SECTION_CONTENT] .
383 PHP_EOL . $tplMysql[self::SECTION_CONTENT] .
384 PHP_EOL . $tplNodejs[self::SECTION_CONTENT] .
385 PHP_EOL . $tplPhp[self::SECTION_CONTENT] .
386 PHP_EOL . $tplPostgresql[self::SECTION_CONTENT] .
387 PHP_EOL . $tplXlight[self::SECTION_CONTENT] .
388 PHP_EOL . $tplApps[self::SECTION_CONTENT] .
389 PHP_EOL . $tplLogs[self::SECTION_CONTENT] .
390 PHP_EOL . $tplTools[self::SECTION_CONTENT] .
391 PHP_EOL . $tplServices[self::SECTION_CONTENT] .
392 PHP_EOL . $tplOnline[self::SECTION_CONTENT];
393 }
394}
$result
global $bearsamppBins
global $bearsamppLang
global $bearsamppRoot
global $bearsamppCore
const CHECK_VERSION
const ABOUT
const EXEC
const STARTUP
const isRoot_FILE
static getWebsiteUrl($path='', $fragment='', $utmSource=true)
const DOCUMENTATION
const MENU_LOCALHOST
const MENU_ABOUT
const MENU_CHECK_UPDATE
const MENU_WWW_DIRECTORY
static getCorePath($aetrayPath=false)
static getWwwPath($aetrayPath=false)
static getPhpExe($aetrayPath=false)
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)
const APP_TITLE
Definition root.php:13