Bearsampp 2026.9.23
Loading...
Searching...
No Matches
class.tpl.app.mailpit.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 = '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
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
60 public static function getMenuMailpit()
61 {
63 $resultItems = $resultActions = '';
64
65 $isEnabled = $bearsamppBins->getMailpit()->isEnable();
66
67 // Download
68 $resultItems .= TplAestan::getItemLink(
70 HttpClient::getWebsiteUrl('module/mailpit', '#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 // Web page
100 $resultItems .= TplAestan::getItemExe(
101 $bearsamppLang->getValue(Lang::MAILPIT),
102 $bearsamppConfig->getBrowser(),
104 Path::getLocalUrl() . ':' . $bearsamppBins->getMailpit()->getUiPort() . '/' . $bearsamppBins->getMailpit()->getWebRoot()
105 ) . PHP_EOL;
106
107 // Log
108 $resultItems .= TplAestan::getItemNotepad($bearsamppLang->getValue(Lang::MENU_LOGS), $bearsamppBins->getMailpit()->getLog()) . PHP_EOL;
109 }
110
111 return $resultItems . PHP_EOL . $resultActions;
112 }
113
123 public static function getMenuMailpitVersions()
124 {
125 global $bearsamppBins;
126 $items = '';
127 $actions = '';
128
129 foreach ($bearsamppBins->getMailpit()->getVersionList() as $version) {
130 $tplSwitchMailpitVersion = TplApp::getActionMulti(
131 self::ACTION_SWITCH_VERSION,
132 array($version),
133 array($version, $version == $bearsamppBins->getMailpit()->getVersion() ? TplAestan::GLYPH_CHECK : ''),
134 false,
135 get_called_class()
136 );
137
138 // Item
139 $items .= $tplSwitchMailpitVersion[TplApp::SECTION_CALL] . PHP_EOL;
140
141 // Action
142 $actions .= PHP_EOL . $tplSwitchMailpitVersion[TplApp::SECTION_CONTENT];
143 }
144
145 return $items . $actions;
146 }
147
159 public static function getActionEnableMailpit($enable)
160 {
161 global $bearsamppBins;
162
163 return TplApp::getActionRun(Action::ENABLE, array($bearsamppBins->getMailpit()->getName(), $enable)) . PHP_EOL .
165 }
166
178 public static function getActionSwitchMailpitVersion($version)
179 {
180 global $bearsamppBins;
181
182 return TplApp::getActionRun(Action::SWITCH_VERSION, array($bearsamppBins->getMailpit()->getName(), $version)) . PHP_EOL .
184 }
185
198 public static function getMenuMailpitService()
199 {
201
202 $tplChangePort = TplApp::getActionMulti(
203 self::ACTION_CHANGE_PORT,
204 null,
206 false,
207 get_called_class()
208 );
209
210 $isInstalled = $bearsamppBins->getMailpit()->getService()->isInstalled();
211
212 $result = TplAestan::getItemActionServiceStart($bearsamppBins->getMailpit()->getService()->getName()) . PHP_EOL .
213 TplAestan::getItemActionServiceStop($bearsamppBins->getMailpit()->getService()->getName()) . PHP_EOL .
214 TplAestan::getItemActionServiceRestart($bearsamppBins->getMailpit()->getService()->getName()) . PHP_EOL .
215 TplAestan::getItemSeparator() . PHP_EOL .
218 array($bearsamppBins->getMailpit()->getName(), $bearsamppBins->getMailpit()->getSmtpPort()),
219 array(sprintf($bearsamppLang->getValue(Lang::MENU_CHECK_PORT), $bearsamppBins->getMailpit()->getSmtpPort()), TplAestan::GLYPH_LIGHT)
220 ) . PHP_EOL .
221 $tplChangePort[TplApp::SECTION_CALL] . PHP_EOL .
222 TplAestan::getItemNotepad($bearsamppLang->getValue(Lang::MENU_UPDATE_ENV_PATH), Path::getRootPath() . '/nssmEnvPaths.dat') . PHP_EOL;
223
224 if (!$isInstalled) {
225 $tplInstallService = TplApp::getActionMulti(
226 self::ACTION_INSTALL_SERVICE,
227 null,
229 $isInstalled,
230 get_called_class()
231 );
232
233 $result .= $tplInstallService[TplApp::SECTION_CALL] . PHP_EOL . PHP_EOL .
234 $tplInstallService[TplApp::SECTION_CONTENT] . PHP_EOL;
235 } else {
236 $tplRemoveService = TplApp::getActionMulti(
237 self::ACTION_REMOVE_SERVICE,
238 null,
240 !$isInstalled,
241 get_called_class()
242 );
243
244 $result .= $tplRemoveService[TplApp::SECTION_CALL] . PHP_EOL . PHP_EOL .
245 $tplRemoveService[TplApp::SECTION_CONTENT] . PHP_EOL;
246 }
247
248 $result .= $tplChangePort[TplApp::SECTION_CONTENT] . PHP_EOL;
249
250 return $result;
251 }
252
262 public static function getActionChangeMailpitPort()
263 {
264 global $bearsamppBins;
265
266 return TplApp::getActionRun(Action::CHANGE_PORT, array($bearsamppBins->getMailpit()->getName())) . PHP_EOL .
268 }
269
282
295}
296
$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 MENU_REMOVE_SERVICE
const MENU_CHECK_PORT
const MAILPIT
const VERSIONS
static getRootPath($aetrayPath=false)
static getLocalUrl($request=null)
static getItemExe($caption, $exe, $glyph, $params=null)
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 getActionInstallMailpitService()
static getActionEnableMailpit($enable)
static getActionChangeMailpitPort()
static getActionRemoveMailpitService()
static getActionSwitchMailpitVersion($version)
global $bearsamppConfig
Definition homepage.php:46