Bearsampp 2026.9.23
Loading...
Searching...
No Matches
class.tpl.app.xlight.php
Go to the documentation of this file.
1<?php
2/*
3 * Copyright (c) 2021-2026 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
18{
19 const MENU = 'xlight';
20 const MENU_VERSIONS = 'xlightVersions';
21 const MENU_SERVICE = 'xlightService';
22
23 const ACTION_ENABLE = 'enableXlight';
24 const ACTION_SWITCH_VERSION = 'switchXlightVersion';
25 const ACTION_CHANGE_PORT = 'changeXlightPort';
26 const ACTION_INSTALL_SERVICE = 'installXlightService';
27 const ACTION_REMOVE_SERVICE = 'removeXlightService';
28
40 public static function process()
41 {
43
44 return TplApp::getMenuEnable($bearsamppLang->getValue(Lang::XLIGHT), self::MENU, get_called_class(), $bearsamppBins->getXlight()->isEnable());
45 }
46
60 public static function getMenuXlight()
61 {
63 $resultItems = $resultActions = '';
64
65 $isEnabled = $bearsamppBins->getXlight()->isEnable();
66
67 // Download
68 $resultItems .= TplAestan::getItemLink(
70 HttpClient::getWebsiteUrl('module/xlight', '#releases'),
71 false,
73 ) . PHP_EOL;
74
75 // Enable
76 $tplEnable = TplApp::getActionMulti(
77 self::ACTION_ENABLE,
78 array($isEnabled ? Config::DISABLED : Config::ENABLED),
79 array($bearsamppLang->getValue(Lang::MENU_ENABLE), $isEnabled ? TplAestan::GLYPH_CHECK : ''),
80 false,
81 get_called_class()
82 );
83 $resultItems .= $tplEnable[TplApp::SECTION_CALL] . PHP_EOL;
84 $resultActions .= $tplEnable[TplApp::SECTION_CONTENT] . PHP_EOL;
85
86 if ($isEnabled) {
87 $resultItems .= TplAestan::getItemSeparator() . PHP_EOL;
88
89 // Versions
90 $tplVersions = TplApp::getMenu($bearsamppLang->getValue(Lang::VERSIONS), self::MENU_VERSIONS, get_called_class());
91 $resultItems .= $tplVersions[TplApp::SECTION_CALL] . PHP_EOL;
92 $resultActions .= $tplVersions[TplApp::SECTION_CONTENT] . PHP_EOL;
93
94 // Service
95 $tplService = TplApp::getMenu($bearsamppLang->getValue(Lang::SERVICE), self::MENU_SERVICE, get_called_class());
96 $resultItems .= $tplService[TplApp::SECTION_CALL] . PHP_EOL;
97 $resultActions .= $tplService[TplApp::SECTION_CONTENT] . PHP_EOL;
98
99 // Log
100 $resultItems .= TplAestan::getItemNotepad($bearsamppLang->getValue(Lang::MENU_LOGS), $bearsamppBins->getXlight()->getLog()) . PHP_EOL;
101 }
102
103 return $resultItems . PHP_EOL . $resultActions;
104 }
105
115 public static function getMenuXlightVersions()
116 {
117 global $bearsamppBins;
118 $items = '';
119 $actions = '';
120
121 foreach ($bearsamppBins->getXlight()->getVersionList() as $version) {
122 $tplSwitchXlightVersion = TplApp::getActionMulti(
123 self::ACTION_SWITCH_VERSION,
124 array($version),
125 array($version, $version == $bearsamppBins->getXlight()->getVersion() ? TplAestan::GLYPH_CHECK : ''),
126 false,
127 get_called_class()
128 );
129
130 // Item
131 $items .= $tplSwitchXlightVersion[TplApp::SECTION_CALL] . PHP_EOL;
132
133 // Action
134 $actions .= PHP_EOL . $tplSwitchXlightVersion[TplApp::SECTION_CONTENT];
135 }
136
137 return $items . $actions;
138 }
139
151 public static function getActionEnableXlight($enable)
152 {
153 global $bearsamppBins;
154
155 return TplApp::getActionRun(Action::ENABLE, array($bearsamppBins->getXlight()->getName(), $enable)) . PHP_EOL .
157 }
158
170 public static function getActionSwitchXlightVersion($version)
171 {
172 global $bearsamppBins;
173
174 return TplApp::getActionRun(Action::SWITCH_VERSION, array($bearsamppBins->getXlight()->getName(), $version)) . PHP_EOL .
176 }
177
190 public static function getMenuXlightService()
191 {
193
194 $tplChangePort = TplApp::getActionMulti(
195 self::ACTION_CHANGE_PORT,
196 null,
198 false,
199 get_called_class()
200 );
201
202 $isInstalled = $bearsamppBins->getXlight()->getService()->isInstalled();
203
204 $result = TplAestan::getItemActionServiceStart($bearsamppBins->getXlight()->getService()->getName()) . PHP_EOL .
205 TplAestan::getItemActionServiceStop($bearsamppBins->getXlight()->getService()->getName()) . PHP_EOL .
206 TplAestan::getItemActionServiceRestart($bearsamppBins->getXlight()->getService()->getName()) . PHP_EOL .
207 TplAestan::getItemSeparator() . PHP_EOL .
210 array($bearsamppBins->getXlight()->getName(), $bearsamppBins->getXlight()->getPort()),
211 array(sprintf($bearsamppLang->getValue(Lang::MENU_CHECK_PORT), $bearsamppBins->getXlight()->getPort()), TplAestan::GLYPH_LIGHT)
212 ) . PHP_EOL .
213 $tplChangePort[TplApp::SECTION_CALL] . PHP_EOL .
214 TplAestan::getItemNotepad($bearsamppLang->getValue(Lang::MENU_UPDATE_ENV_PATH), Path::getRootPath() . '/nssmEnvPaths.dat') . PHP_EOL;
215
216 if (!$isInstalled) {
217 $tplInstallService = TplApp::getActionMulti(
218 self::ACTION_INSTALL_SERVICE,
219 null,
221 $isInstalled,
222 get_called_class()
223 );
224
225 $result .= $tplInstallService[TplApp::SECTION_CALL] . PHP_EOL . PHP_EOL .
226 $tplInstallService[TplApp::SECTION_CONTENT] . PHP_EOL;
227 } else {
228 $tplRemoveService = TplApp::getActionMulti(
229 self::ACTION_REMOVE_SERVICE,
230 null,
232 !$isInstalled,
233 get_called_class()
234 );
235
236 $result .= $tplRemoveService[TplApp::SECTION_CALL] . PHP_EOL . PHP_EOL .
237 $tplRemoveService[TplApp::SECTION_CONTENT] . PHP_EOL;
238 }
239
240 $result .= $tplChangePort[TplApp::SECTION_CONTENT] . PHP_EOL;
241
242 return $result;
243 }
244
254 public static function getActionChangeXlightPort()
255 {
256 global $bearsamppBins;
257
258 return TplApp::getActionRun(Action::CHANGE_PORT, array($bearsamppBins->getXlight()->getName())) . PHP_EOL .
260 }
261
274
287}
288
$result
global $bearsamppBins
global $bearsamppLang
global $bearsamppRoot
const SWITCH_VERSION
const SERVICE
const CHANGE_PORT
const CHECK_PORT
const ENABLE
const DISABLED
const ENABLED
static getWebsiteUrl($path='', $fragment='', $utmSource=true)
const MENU_ENABLE
const SERVICE
const DOWNLOAD_MORE
const MENU_CHANGE_PORT
const MENU_INSTALL_SERVICE
const MENU_UPDATE_ENV_PATH
const MENU_LOGS
const XLIGHT
const MENU_REMOVE_SERVICE
const MENU_CHECK_PORT
const VERSIONS
static getRootPath($aetrayPath=false)
const GLYPH_SERVICE_REMOVE
static getItemActionServiceStop($service)
const GLYPH_SERVICE_INSTALL
static getItemLink($caption, $link, $local=false, $glyph=self::GLYPH_WEB_PAGE)
static getItemNotepad($caption, $path)
static getItemActionServiceStart($service)
static getItemSeparator()
static getItemActionServiceRestart($service)
static getActionMulti($action, $args=array(), $item=array(), $disabled=false, $class=false)
static getMenu($caption, $menu, $class)
static getActionRun($action, $args=array(), $item=array(), $waitUntilTerminated=true)
const SECTION_CALL
const SECTION_CONTENT
static getMenuEnable($caption, $menu, $class, $enabled=true)
static getActionChangeXlightPort()
static getActionEnableXlight($enable)
static getActionRemoveXlightService()
static getActionSwitchXlightVersion($version)
static getActionInstallXlightService()
global $bearsamppConfig
Definition homepage.php:46