2024.8.23
Loading...
Searching...
No Matches
class.tpl.app.mailpit.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 TplAppMailpit
12 *
13 * This class provides methods to generate menus and actions for managing the Mailpit application.
14 * It includes functionalities for enabling/disabling Mailpit, switching versions, changing ports,
15 * and managing the Mailpit service.
16 */
18{
19 const MENU = 'mailpit';
20 const MENU_VERSIONS = 'mailpitVersions';
21 const MENU_SERVICE = 'mailpitService';
22
23 const ACTION_ENABLE = 'enableMailpit';
24 const ACTION_SWITCH_VERSION = 'switchMailpitVersion';
25 const ACTION_CHANGE_PORT = 'changeMailpitPort';
26 const ACTION_INSTALL_SERVICE = 'installMailpitService';
27 const ACTION_REMOVE_SERVICE = 'removeMailpitService';
28
29 /**
30 * Processes the Mailpit menu.
31 *
32 * This method generates the menu for enabling or disabling Mailpit.
33 * It uses the global language object to retrieve the localized string for Mailpit.
34 *
35 * @global object $bearsamppLang Provides language support for retrieving language-specific values.
36 * @global object $bearsamppBins Provides access to system binaries and their configurations.
37 *
38 * @return array The generated menu for enabling or disabling Mailpit.
39 */
40 public static function process()
41 {
43
44 return TplApp::getMenuEnable($bearsamppLang->getValue(Lang::MAILPIT), self::MENU, get_called_class(), $bearsamppBins->getMailpit()->isEnable());
45 }
46
47 /**
48 * Generates the Mailpit menu.
49 *
50 * This method creates the menu items and associated actions for Mailpit, including options for downloading,
51 * enabling, switching versions, managing the service, and viewing logs.
52 *
53 * @global object $bearsamppRoot Provides access to the root path of the application.
54 * @global object $bearsamppConfig Provides access to the application configuration.
55 * @global object $bearsamppBins Provides access to system binaries and their configurations.
56 * @global object $bearsamppLang Provides language support for retrieving language-specific values.
57 *
58 * @return string The generated Mailpit menu items and actions.
59 */
60 public static function getMenuMailpit()
61 {
63 $resultItems = $resultActions = '';
64
65 $isEnabled = $bearsamppBins->getMailpit()->isEnable();
66
67 // Download
68 $resultItems .= TplAestan::getItemLink(
70 Util::getWebsiteUrl('module/mailpit', '#releases'),
71 false,
73 ) . PHP_EOL;
74
75 // Enable
76 $tplEnable = TplApp::getActionMulti(
77 self::ACTION_ENABLE, array($isEnabled ? Config::DISABLED : Config::ENABLED),
78 array($bearsamppLang->getValue(Lang::MENU_ENABLE), $isEnabled ? TplAestan::GLYPH_CHECK : ''),
79 false, get_called_class()
80 );
81 $resultItems .= $tplEnable[TplApp::SECTION_CALL] . PHP_EOL;
82 $resultActions .= $tplEnable[TplApp::SECTION_CONTENT] . PHP_EOL;
83
84 if ($isEnabled) {
85 $resultItems .= TplAestan::getItemSeparator() . PHP_EOL;
86
87 // Versions
88 $tplVersions = TplApp::getMenu($bearsamppLang->getValue(Lang::VERSIONS), self::MENU_VERSIONS, get_called_class());
89 $resultItems .= $tplVersions[TplApp::SECTION_CALL] . PHP_EOL;
90 $resultActions .= $tplVersions[TplApp::SECTION_CONTENT] . PHP_EOL;
91
92 // Service
93 $tplService = TplApp::getMenu($bearsamppLang->getValue(Lang::SERVICE), self::MENU_SERVICE, get_called_class());
94 $resultItems .= $tplService[TplApp::SECTION_CALL] . PHP_EOL;
95 $resultActions .= $tplService[TplApp::SECTION_CONTENT] . PHP_EOL;
96
97 // Web page
98 $resultItems .= TplAestan::getItemExe(
100 $bearsamppConfig->getBrowser(),
102 $bearsamppRoot->getLocalUrl() . ':' . $bearsamppBins->getMailpit()->getUiPort() . '/' . $bearsamppBins->getMailpit()->getWebRoot()
103 ) . PHP_EOL;
104
105 // Log
106 $resultItems .= TplAestan::getItemNotepad($bearsamppLang->getValue(Lang::MENU_LOGS), $bearsamppBins->getMailpit()->getLog()) . PHP_EOL;
107 }
108
109 return $resultItems . PHP_EOL . $resultActions;
110 }
111
112 /**
113 * Generates the Mailpit versions menu.
114 *
115 * This method creates the menu items and associated actions for switching between different versions of Mailpit.
116 *
117 * @global object $bearsamppBins Provides access to system binaries and their configurations.
118 *
119 * @return string The generated Mailpit versions menu items and actions.
120 */
121 public static function getMenuMailpitVersions()
122 {
123 global $bearsamppBins;
124 $items = '';
125 $actions = '';
126
127 foreach ($bearsamppBins->getMailpit()->getVersionList() as $version) {
128 $tplSwitchMailpitVersion = TplApp::getActionMulti(
129 self::ACTION_SWITCH_VERSION, array($version),
130 array($version, $version == $bearsamppBins->getMailpit()->getVersion() ? TplAestan::GLYPH_CHECK : ''),
131 false, get_called_class()
132 );
133
134 // Item
135 $items .= $tplSwitchMailpitVersion[TplApp::SECTION_CALL] . PHP_EOL;
136
137 // Action
138 $actions .= PHP_EOL . $tplSwitchMailpitVersion[TplApp::SECTION_CONTENT];
139 }
140
141 return $items . $actions;
142 }
143
144 /**
145 * Generates the action to enable or disable Mailpit.
146 *
147 * This method creates the action string for enabling or disabling Mailpit and includes a command to reload the application.
148 *
149 * @global object $bearsamppBins Provides access to system binaries and their configurations.
150 *
151 * @param int $enable The enable flag (1 to enable, 0 to disable).
152 * @return string The generated action string for enabling or disabling Mailpit.
153 */
154 public static function getActionEnableMailpit($enable)
155 {
156 global $bearsamppBins;
157
158 return TplApp::getActionRun(Action::ENABLE, array($bearsamppBins->getMailpit()->getName(), $enable)) . PHP_EOL .
160 }
161
162 /**
163 * Generates the action to switch the Mailpit version.
164 *
165 * This method creates the action string for switching the Mailpit version and includes a command to reload the application.
166 *
167 * @global object $bearsamppBins Provides access to system binaries and their configurations.
168 *
169 * @param string $version The version to switch to.
170 * @return string The generated action string for switching the Mailpit version.
171 */
172 public static function getActionSwitchMailpitVersion($version)
173 {
174 global $bearsamppBins;
175
176 return TplApp::getActionRun(Action::SWITCH_VERSION, array($bearsamppBins->getMailpit()->getName(), $version)) . PHP_EOL .
178 }
179
180 /**
181 * Generates the Mailpit service menu.
182 *
183 * This method creates the menu items and associated actions for managing the Mailpit service, including starting, stopping,
184 * restarting, changing ports, and installing or removing the service.
185 *
186 * @global object $bearsamppRoot Provides access to the root path of the application.
187 * @global object $bearsamppLang Provides language support for retrieving language-specific values.
188 * @global object $bearsamppBins Provides access to system binaries and their configurations.
189 *
190 * @return string The generated Mailpit service menu items and actions.
191 */
192 public static function getMenuMailpitService()
193 {
195
196 $tplChangePort = TplApp::getActionMulti(
197 self::ACTION_CHANGE_PORT, null,
199 false, get_called_class()
200 );
201
202 $isInstalled = $bearsamppBins->getMailpit()->getService()->isInstalled();
203
204 $result = TplAestan::getItemActionServiceStart($bearsamppBins->getMailpit()->getService()->getName()) . PHP_EOL .
205 TplAestan::getItemActionServiceStop($bearsamppBins->getMailpit()->getService()->getName()) . PHP_EOL .
206 TplAestan::getItemActionServiceRestart($bearsamppBins->getMailpit()->getService()->getName()) . PHP_EOL .
207 TplAestan::getItemSeparator() . PHP_EOL .
209 Action::CHECK_PORT, array($bearsamppBins->getMailpit()->getName(), $bearsamppBins->getMailpit()->getSmtpPort()),
210 array(sprintf($bearsamppLang->getValue(Lang::MENU_CHECK_PORT), $bearsamppBins->getMailpit()->getSmtpPort()), TplAestan::GLYPH_LIGHT)
211 ) . PHP_EOL .
212 $tplChangePort[TplApp::SECTION_CALL] . PHP_EOL .
213 TplAestan::getItemNotepad($bearsamppLang->getValue(Lang::MENU_UPDATE_ENV_PATH), $bearsamppRoot->getRootPath() . '/nssmEnvPaths.dat') . PHP_EOL;
214
215 if (!$isInstalled) {
216 $tplInstallService = TplApp::getActionMulti(
217 self::ACTION_INSTALL_SERVICE, null,
219 $isInstalled, get_called_class()
220 );
221
222 $result .= $tplInstallService[TplApp::SECTION_CALL] . PHP_EOL . PHP_EOL .
223 $tplInstallService[TplApp::SECTION_CONTENT] . PHP_EOL;
224 } else {
225 $tplRemoveService = TplApp::getActionMulti(
226 self::ACTION_REMOVE_SERVICE, null,
228 !$isInstalled, get_called_class()
229 );
230
231 $result .= $tplRemoveService[TplApp::SECTION_CALL] . PHP_EOL . PHP_EOL .
232 $tplRemoveService[TplApp::SECTION_CONTENT] . PHP_EOL;
233 }
234
235 $result .= $tplChangePort[TplApp::SECTION_CONTENT] . PHP_EOL;
236
237 return $result;
238 }
239
240 /**
241 * Generates the action to change the Mailpit port.
242 *
243 * This method creates the action string for changing the Mailpit port and includes a command to reload the application.
244 *
245 * @global object $bearsamppBins Provides access to system binaries and their configurations.
246 *
247 * @return string The generated action string for changing the Mailpit port.
248 */
249 public static function getActionChangeMailpitPort()
250 {
251 global $bearsamppBins;
252
253 return TplApp::getActionRun(Action::CHANGE_PORT, array($bearsamppBins->getMailpit()->getName())) . PHP_EOL .
255 }
256
257 /**
258 * Generates the action to install the Mailpit service.
259 *
260 * This method creates the action string for installing the Mailpit service and includes a command to reload the application.
261 *
262 * @return string The generated action string for installing the Mailpit service.
263 */
269
270 /**
271 * Generates the action to remove the Mailpit service.
272 *
273 * This method creates the action string for removing the Mailpit service and includes a command to reload the application.
274 *
275 * @return string The generated action string for removing the Mailpit service.
276 */
282}
$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 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 MAILPIT
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)
static getItemExe($caption, $exe, $glyph, $params=null)
const GLYPH_SERVICE_INSTALL
static getItemNotepad($caption, $path)
static getActionChangeMailpitPort()
static getActionInstallMailpitService()
static getActionSwitchMailpitVersion($version)
static getActionEnableMailpit($enable)
static getActionRemoveMailpitService()
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