2024.8.23
Loading...
Searching...
No Matches
class.tpl.app.xlight.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
11{
12 const MENU = 'xlight';
13 const MENU_VERSIONS = 'xlightVersions';
14 const MENU_SERVICE = 'xlightService';
15
16 const ACTION_ENABLE = 'enableXlight';
17 const ACTION_SWITCH_VERSION = 'switchXlightVersion';
18 const ACTION_CHANGE_PORT = 'changeXlightPort';
19 const ACTION_INSTALL_SERVICE = 'installXlightService';
20 const ACTION_REMOVE_SERVICE = 'removeXlightService';
21
22 /**
23 * Processes the Xlight menu.
24 *
25 * This method generates the menu for enabling or disabling Xlight.
26 * It uses the global language object to retrieve the localized string for Xlight.
27 *
28 * @global object $bearsamppLang Provides language support for retrieving language-specific values.
29 * @global object $bearsamppBins Provides access to system binaries and their configurations.
30 *
31 * @return array The generated menu for enabling or disabling Xlight.
32 */
33 public static function process()
34 {
36
37 return TplApp::getMenuEnable($bearsamppLang->getValue(Lang::XLIGHT), self::MENU, get_called_class(), $bearsamppBins->getXlight()->isEnable());
38 }
39
40 /**
41 * Generates the Xlight menu.
42 *
43 * This method creates the menu items and associated actions for Xlight, including options for downloading,
44 * enabling, switching versions, managing the service, and viewing logs.
45 *
46 * @global object $bearsamppRoot Provides access to the root path of the application.
47 * @global object $bearsamppConfig Provides access to the application configuration.
48 * @global object $bearsamppBins Provides access to system binaries and their configurations.
49 * @global object $bearsamppLang Provides language support for retrieving language-specific values.
50 *
51 * @return string The generated Xlight menu items and actions.
52 */
53 public static function getMenuXlight()
54 {
56 $resultItems = $resultActions = '';
57
58 $isEnabled = $bearsamppBins->getXlight()->isEnable();
59
60 // Download
61 $resultItems .= TplAestan::getItemLink(
63 Util::getWebsiteUrl('module/xlight', '#releases'),
64 false,
66 ) . PHP_EOL;
67
68 // Enable
69 $tplEnable = TplApp::getActionMulti(
70 self::ACTION_ENABLE, array($isEnabled ? Config::DISABLED : Config::ENABLED),
71 array($bearsamppLang->getValue(Lang::MENU_ENABLE), $isEnabled ? TplAestan::GLYPH_CHECK : ''),
72 false, get_called_class()
73 );
74 $resultItems .= $tplEnable[TplApp::SECTION_CALL] . PHP_EOL;
75 $resultActions .= $tplEnable[TplApp::SECTION_CONTENT] . PHP_EOL;
76
77 if ($isEnabled) {
78 $resultItems .= TplAestan::getItemSeparator() . PHP_EOL;
79
80 // Versions
81 $tplVersions = TplApp::getMenu($bearsamppLang->getValue(Lang::VERSIONS), self::MENU_VERSIONS, get_called_class());
82 $resultItems .= $tplVersions[TplApp::SECTION_CALL] . PHP_EOL;
83 $resultActions .= $tplVersions[TplApp::SECTION_CONTENT] . PHP_EOL;
84
85 // Service
86 $tplService = TplApp::getMenu($bearsamppLang->getValue(Lang::SERVICE), self::MENU_SERVICE, get_called_class());
87 $resultItems .= $tplService[TplApp::SECTION_CALL] . PHP_EOL;
88 $resultActions .= $tplService[TplApp::SECTION_CONTENT] . PHP_EOL;
89
90 // Log
91 $resultItems .= TplAestan::getItemNotepad($bearsamppLang->getValue(Lang::MENU_LOGS), $bearsamppBins->getXlight()->getLog()) . PHP_EOL;
92 }
93
94 return $resultItems . PHP_EOL . $resultActions;
95 }
96
97 /**
98 * Generates the Xlight versions menu.
99 *
100 * This method creates the menu items and associated actions for switching between different versions of Xlight.
101 *
102 * @global object $bearsamppBins Provides access to system binaries and their configurations.
103 *
104 * @return string The generated Xlight versions menu items and actions.
105 */
106 public static function getMenuXlightVersions()
107 {
108 global $bearsamppBins;
109 $items = '';
110 $actions = '';
111
112 foreach ($bearsamppBins->getXlight()->getVersionList() as $version) {
113 $tplSwitchXlightVersion = TplApp::getActionMulti(
114 self::ACTION_SWITCH_VERSION, array($version),
115 array($version, $version == $bearsamppBins->getXlight()->getVersion() ? TplAestan::GLYPH_CHECK : ''),
116 false, get_called_class()
117 );
118
119 // Item
120 $items .= $tplSwitchXlightVersion[TplApp::SECTION_CALL] . PHP_EOL;
121
122 // Action
123 $actions .= PHP_EOL . $tplSwitchXlightVersion[TplApp::SECTION_CONTENT];
124 }
125
126 return $items . $actions;
127 }
128
129 /**
130 * Generates the action to enable or disable Xlight.
131 *
132 * This method creates the action string for enabling or disabling Xlight and includes a command to reload the application.
133 *
134 * @global object $bearsamppBins Provides access to system binaries and their configurations.
135 *
136 * @param int $enable The enable flag (1 to enable, 0 to disable).
137 * @return string The generated action string for enabling or disabling Xlight.
138 */
139 public static function getActionEnableXlight($enable)
140 {
141 global $bearsamppBins;
142
143 return TplApp::getActionRun(Action::ENABLE, array($bearsamppBins->getXlight()->getName(), $enable)) . PHP_EOL .
145 }
146
147 /**
148 * Generates the action to switch the Xlight version.
149 *
150 * This method creates the action string for switching the Xlight version and includes a command to reload the application.
151 *
152 * @global object $bearsamppBins Provides access to system binaries and their configurations.
153 *
154 * @param string $version The version to switch to.
155 * @return string The generated action string for switching the Xlight version.
156 */
157 public static function getActionSwitchXlightVersion($version)
158 {
159 global $bearsamppBins;
160
161 return TplApp::getActionRun(Action::SWITCH_VERSION, array($bearsamppBins->getXlight()->getName(), $version)) . PHP_EOL .
163 }
164
165 /**
166 * Generates the Xlight service menu.
167 *
168 * This method creates the menu items and associated actions for managing the Xlight service, including starting, stopping,
169 * restarting, changing ports, and installing or removing the service.
170 *
171 * @global object $bearsamppRoot Provides access to the root path of the application.
172 * @global object $bearsamppLang Provides language support for retrieving language-specific values.
173 * @global object $bearsamppBins Provides access to system binaries and their configurations.
174 *
175 * @return string The generated Xlight service menu items and actions.
176 */
177 public static function getMenuXlightService()
178 {
180
181 $tplChangePort = TplApp::getActionMulti(
182 self::ACTION_CHANGE_PORT, null,
184 false, get_called_class()
185 );
186
187 $isInstalled = $bearsamppBins->getXlight()->getService()->isInstalled();
188
189 $result = TplAestan::getItemActionServiceStart($bearsamppBins->getXlight()->getService()->getName()) . PHP_EOL .
190 TplAestan::getItemActionServiceStop($bearsamppBins->getXlight()->getService()->getName()) . PHP_EOL .
191 TplAestan::getItemActionServiceRestart($bearsamppBins->getXlight()->getService()->getName()) . PHP_EOL .
192 TplAestan::getItemSeparator() . PHP_EOL .
194 Action::CHECK_PORT, array($bearsamppBins->getXlight()->getName(), $bearsamppBins->getXlight()->getPort()),
195 array(sprintf($bearsamppLang->getValue(Lang::MENU_CHECK_PORT), $bearsamppBins->getXlight()->getPort()), TplAestan::GLYPH_LIGHT)
196 ) . PHP_EOL .
197 $tplChangePort[TplApp::SECTION_CALL] . PHP_EOL .
198 TplAestan::getItemNotepad($bearsamppLang->getValue(Lang::MENU_UPDATE_ENV_PATH), $bearsamppRoot->getRootPath() . '/nssmEnvPaths.dat') . PHP_EOL;
199
200 if (!$isInstalled) {
201 $tplInstallService = TplApp::getActionMulti(
202 self::ACTION_INSTALL_SERVICE, null,
204 $isInstalled, get_called_class()
205 );
206
207 $result .= $tplInstallService[TplApp::SECTION_CALL] . PHP_EOL . PHP_EOL .
208 $tplInstallService[TplApp::SECTION_CONTENT] . PHP_EOL;
209 } else {
210 $tplRemoveService = TplApp::getActionMulti(
211 self::ACTION_REMOVE_SERVICE, null,
213 !$isInstalled, get_called_class()
214 );
215
216 $result .= $tplRemoveService[TplApp::SECTION_CALL] . PHP_EOL . PHP_EOL .
217 $tplRemoveService[TplApp::SECTION_CONTENT] . PHP_EOL;
218 }
219
220 $result .= $tplChangePort[TplApp::SECTION_CONTENT] . PHP_EOL;
221
222 return $result;
223 }
224
225 /**
226 * Generates the action to change the Xlight port.
227 *
228 * This method creates the action string for changing the Xlight port and includes a command to reload the application.
229 *
230 * @global object $bearsamppBins Provides access to system binaries and their configurations.
231 *
232 * @return string The generated action string for changing the Xlight port.
233 */
234 public static function getActionChangeXlightPort()
235 {
236 global $bearsamppBins;
237
238 return TplApp::getActionRun(Action::CHANGE_PORT, array($bearsamppBins->getXlight()->getName())) . PHP_EOL .
240 }
241
242 /**
243 * Generates the action to install the Xlight service.
244 *
245 * This method creates the action string for installing the Xlight service and includes a command to reload the application.
246 *
247 * @return string The generated action string for installing the Xlight service.
248 */
254
255 /**
256 * Generates the action to remove the Xlight service.
257 *
258 * This method creates the action string for removing the Xlight service and includes a command to reload the application.
259 *
260 * @return string The generated action string for removing the Xlight service.
261 */
267}
$result
global $bearsamppBins
global $bearsamppLang
global $bearsamppRoot
const CHANGE_PORT
const CHECK_PORT
const ENABLE
const SWITCH_VERSION
const SERVICE
const DISABLED
const ENABLED
const MENU_LOGS
const XLIGHT
const VERSIONS
const MENU_INSTALL_SERVICE
const MENU_UPDATE_ENV_PATH
const MENU_ENABLE
const DOWNLOAD_MORE
const MENU_REMOVE_SERVICE
const MENU_CHECK_PORT
const SERVICE
const MENU_CHANGE_PORT
const GLYPH_SERVICE_REMOVE
static getItemActionServiceStop($service)
static getItemSeparator()
static getItemActionServiceStart($service)
static getItemActionServiceRestart($service)
static getItemLink($caption, $link, $local=false, $glyph=self::GLYPH_WEB_PAGE)
const GLYPH_SERVICE_INSTALL
static getItemNotepad($caption, $path)
static getActionSwitchXlightVersion($version)
static getActionRemoveXlightService()
static getActionChangeXlightPort()
static getActionInstallXlightService()
static getActionEnableXlight($enable)
static getActionMulti($action, $args=array(), $item=array(), $disabled=false, $class=false)
const SECTION_CALL
static getMenuEnable($caption, $menu, $class, $enabled=true)
const SECTION_CONTENT
static getActionRun($action, $args=array(), $item=array(), $waitUntilTerminated=true)
static getMenu($caption, $menu, $class)
static getWebsiteUrl($path='', $fragment='', $utmSource=true)
global $bearsamppConfig
Definition homepage.php:26