2024.8.23
Loading...
Searching...
No Matches
class.tpl.app.filezilla.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
10/**
11 * Class TplAppFilezilla
12 *
13 * This class provides methods to generate actions and menu items for managing the Filezilla module in the Bearsampp application.
14 * It includes functionalities for enabling/disabling Filezilla, switching versions, changing ports, and managing services.
15 */
17{
18 const MENU = 'filezilla';
19 const MENU_VERSIONS = 'filezillaVersions';
20 const MENU_SERVICE = 'filezillaService';
21
22 const ACTION_ENABLE = 'enableFilezilla';
23 const ACTION_SWITCH_VERSION = 'switchFilezillaVersion';
24 const ACTION_CHANGE_PORT = 'changeFilezillaPort';
25 const ACTION_INSTALL_SERVICE = 'installFilezillaService';
26 const ACTION_REMOVE_SERVICE = 'removeFilezillaService';
27
28 /**
29 * Generates the menu item and associated actions for enabling/disabling Filezilla.
30 *
31 * @global object $bearsamppLang Provides language support for retrieving language-specific values.
32 * @global object $bearsamppBins Provides access to system binaries and their configurations.
33 *
34 * @return array The generated menu item and actions for enabling/disabling Filezilla.
35 */
36 public static function process()
37 {
39
40 return TplApp::getMenuEnable($bearsamppLang->getValue(Lang::FILEZILLA), self::MENU, get_called_class(), $bearsamppBins->getFilezilla()->isEnable());
41 }
42
43 /**
44 * Generates the menu items and actions for managing Filezilla.
45 *
46 * This method creates menu items for downloading, enabling/disabling, switching versions, managing services,
47 * accessing the admin interface, and viewing logs for Filezilla.
48 *
49 * @global object $bearsamppBins Provides access to system binaries and their configurations.
50 * @global object $bearsamppLang Provides language support for retrieving language-specific values.
51 *
52 * @return string The generated menu items and actions for managing Filezilla.
53 */
54 public static function getMenuFilezilla()
55 {
57 $resultItems = $resultActions = '';
58
59 $isEnabled = $bearsamppBins->getFilezilla()->isEnable();
60
61 // Download
62 $resultItems .= TplAestan::getItemLink(
64 Util::getWebsiteUrl('module/filezilla', '#releases'),
65 false,
67 ) . PHP_EOL;
68
69 // Enable
70 $tplEnable = TplApp::getActionMulti(
71 self::ACTION_ENABLE, array($isEnabled ? Config::DISABLED : Config::ENABLED),
72 array($bearsamppLang->getValue(Lang::MENU_ENABLE), $isEnabled ? TplAestan::GLYPH_CHECK : ''),
73 false, get_called_class()
74 );
75 $resultItems .= $tplEnable[TplApp::SECTION_CALL] . PHP_EOL;
76 $resultActions .= $tplEnable[TplApp::SECTION_CONTENT] . PHP_EOL;
77
78 if ($isEnabled) {
79 $resultItems .= TplAestan::getItemSeparator() . PHP_EOL;
80
81 // Versions
82 $tplVersions = TplApp::getMenu($bearsamppLang->getValue(Lang::VERSIONS), self::MENU_VERSIONS, get_called_class());
83 $resultItems .= $tplVersions[TplApp::SECTION_CALL] . PHP_EOL;
84 $resultActions .= $tplVersions[TplApp::SECTION_CONTENT] . PHP_EOL;
85
86 // Service
87 $tplService = TplApp::getMenu($bearsamppLang->getValue(Lang::SERVICE), self::MENU_SERVICE, get_called_class());
88 $resultItems .= $tplService[TplApp::SECTION_CALL] . PHP_EOL;
89 $resultActions .= $tplService[TplApp::SECTION_CONTENT];
90
91 // Admin interface
92 $resultItems .= TplAestan::getItemExe(
94 $bearsamppBins->getFilezilla()->getItfExe(),
96 ) . PHP_EOL;
97
98 // Log
99 $resultItems .= TplAestan::getItemNotepad($bearsamppLang->getValue(Lang::MENU_LOGS), $bearsamppBins->getFilezilla()->getLog()) . PHP_EOL;
100 }
101
102 return $resultItems . PHP_EOL . $resultActions;
103 }
104
105 /**
106 * Generates the menu items and actions for switching Filezilla versions.
107 *
108 * This method creates menu items for each available version of Filezilla, allowing the user to switch between them.
109 *
110 * @global object $bearsamppBins Provides access to system binaries and their configurations.
111 *
112 * @return string The generated menu items and actions for switching Filezilla versions.
113 */
114 public static function getMenuFilezillaVersions()
115 {
116 global $bearsamppBins;
117 $items = '';
118 $actions = '';
119
120 foreach ($bearsamppBins->getFilezilla()->getVersionList() as $version) {
121 $tplSwitchFilezillaVersion = TplApp::getActionMulti(
122 self::ACTION_SWITCH_VERSION, array($version),
123 array($version, $version == $bearsamppBins->getFilezilla()->getVersion() ? TplAestan::GLYPH_CHECK : ''),
124 false, get_called_class()
125 );
126
127 // Item
128 $items .= $tplSwitchFilezillaVersion[TplApp::SECTION_CALL] . PHP_EOL;
129
130 // Action
131 $actions .= PHP_EOL . $tplSwitchFilezillaVersion[TplApp::SECTION_CONTENT];
132 }
133
134 return $items . $actions;
135 }
136
137 /**
138 * Generates the action to enable or disable Filezilla.
139 *
140 * This method creates the action string for enabling or disabling Filezilla, and includes a command to reload the application.
141 *
142 * @global object $bearsamppBins Provides access to system binaries and their configurations.
143 *
144 * @param int $enable The enable/disable flag (1 for enable, 0 for disable).
145 * @return string The generated action string for enabling/disabling Filezilla.
146 */
147 public static function getActionEnableFilezilla($enable)
148 {
149 global $bearsamppBins;
150
151 return TplApp::getActionRun(Action::ENABLE, array($bearsamppBins->getFilezilla()->getName(), $enable)) . PHP_EOL .
153 }
154
155 /**
156 * Generates the action to switch Filezilla versions.
157 *
158 * This method creates the action string for switching Filezilla versions, and includes a command to reload the application.
159 *
160 * @global object $bearsamppBins Provides access to system binaries and their configurations.
161 *
162 * @param string $version The version to switch to.
163 * @return string The generated action string for switching Filezilla versions.
164 */
165 public static function getActionSwitchFilezillaVersion($version)
166 {
167 global $bearsamppBins;
168
169 return TplApp::getActionRun(Action::SWITCH_VERSION, array($bearsamppBins->getFilezilla()->getName(), $version)) . PHP_EOL .
171 }
172
173 /**
174 * Generates the menu items and actions for managing Filezilla services.
175 *
176 * This method creates menu items for starting, stopping, restarting, checking ports, changing ports, and installing/removing the Filezilla service.
177 *
178 * @global object $bearsamppLang Provides language support for retrieving language-specific values.
179 * @global object $bearsamppBins Provides access to system binaries and their configurations.
180 *
181 * @return string The generated menu items and actions for managing Filezilla services.
182 */
183 public static function getMenuFilezillaService()
184 {
186
187 $tplChangePort = TplApp::getActionMulti(
188 self::ACTION_CHANGE_PORT, null,
190 false, get_called_class()
191 );
192
193 $result = TplAestan::getItemActionServiceStart($bearsamppBins->getFilezilla()->getService()->getName()) . PHP_EOL .
194 TplAestan::getItemActionServiceStop($bearsamppBins->getFilezilla()->getService()->getName()) . PHP_EOL .
195 TplAestan::getItemActionServiceRestart($bearsamppBins->getFilezilla()->getService()->getName()) . PHP_EOL .
196 TplAestan::getItemSeparator() . PHP_EOL .
198 Action::CHECK_PORT, array($bearsamppBins->getFilezilla()->getName(), $bearsamppBins->getFilezilla()->getPort()),
199 array(sprintf($bearsamppLang->getValue(Lang::MENU_CHECK_PORT), $bearsamppBins->getFilezilla()->getPort()), TplAestan::GLYPH_LIGHT)
200 ) . PHP_EOL .
202 Action::CHECK_PORT, array($bearsamppBins->getFilezilla()->getName(), $bearsamppBins->getFilezilla()->getSslPort(), true),
203 array(sprintf($bearsamppLang->getValue(Lang::MENU_CHECK_PORT), $bearsamppBins->getFilezilla()->getSslPort()) . ' (SSL)', TplAestan::GLYPH_RED_LIGHT)
204 ) . PHP_EOL .
205 $tplChangePort[TplApp::SECTION_CALL] . PHP_EOL;
206
207 $isInstalled = $bearsamppBins->getFilezilla()->getService()->isInstalled();
208 if (!$isInstalled) {
209 $tplInstallService = TplApp::getActionMulti(
210 self::ACTION_INSTALL_SERVICE, null,
212 $isInstalled, get_called_class()
213 );
214
215 $result .= $tplInstallService[TplApp::SECTION_CALL] . PHP_EOL . PHP_EOL .
216 $tplInstallService[TplApp::SECTION_CONTENT] . PHP_EOL;
217 } else {
218 $tplRemoveService = TplApp::getActionMulti(
219 self::ACTION_REMOVE_SERVICE, null,
221 !$isInstalled, get_called_class()
222 );
223
224 $result .= $tplRemoveService[TplApp::SECTION_CALL] . PHP_EOL . PHP_EOL .
225 $tplRemoveService[TplApp::SECTION_CONTENT] . PHP_EOL;
226 }
227
228 $result .= $tplChangePort[TplApp::SECTION_CONTENT] . PHP_EOL;
229
230 return $result;
231 }
232
233 /**
234 * Generates the action to change the Filezilla port.
235 *
236 * This method creates the action string for changing the Filezilla port, and includes a command to reload the application.
237 *
238 * @global object $bearsamppBins Provides access to system binaries and their configurations.
239 *
240 * @return string The generated action string for changing the Filezilla port.
241 */
242 public static function getActionChangeFilezillaPort()
243 {
244 global $bearsamppBins;
245
246 return TplApp::getActionRun(Action::CHANGE_PORT, array($bearsamppBins->getFilezilla()->getName())) . PHP_EOL .
248 }
249
250 /**
251 * Generates the action to install the Filezilla service.
252 *
253 * This method creates the action string for installing the Filezilla service, and includes a command to reload the application.
254 *
255 * @return string The generated action string for installing the Filezilla service.
256 */
262
263 /**
264 * Generates the action to remove the Filezilla service.
265 *
266 * This method creates the action string for removing the Filezilla service, and includes a command to reload the application.
267 *
268 * @return string The generated action string for removing the Filezilla service.
269 */
275}
$result
global $bearsamppBins
global $bearsamppLang
const CHANGE_PORT
const CHECK_PORT
const ENABLE
const SWITCH_VERSION
const SERVICE
const DISABLED
const ENABLED
const MENU_LOGS
const VERSIONS
const MENU_INSTALL_SERVICE
const MENU_ENABLE
const DOWNLOAD_MORE
const ADMINISTRATION
const MENU_REMOVE_SERVICE
const FILEZILLA
const MENU_CHECK_PORT
const SERVICE
const MENU_CHANGE_PORT
const GLYPH_SERVICE_REMOVE
static getItemActionServiceStop($service)
static getItemSeparator()
static getItemActionServiceStart($service)
const GLYPH_RED_LIGHT
static getItemActionServiceRestart($service)
const GLYPH_FILEZILLA
static getItemLink($caption, $link, $local=false, $glyph=self::GLYPH_WEB_PAGE)
static getItemExe($caption, $exe, $glyph, $params=null)
const GLYPH_SERVICE_INSTALL
static getItemNotepad($caption, $path)
static getActionEnableFilezilla($enable)
static getActionSwitchFilezillaVersion($version)
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)